Skip to content

๐Ÿ“‹ HTTP Headers with RapidTest

Introduction to HTTP headers, learn when and how to use the most important ones in your API. โšก

๐Ÿ“– Overview

HTTP headers provide essential metadata about requests and responses, headers exist for authentication, content negotiation, and more.

1. ๐Ÿ” Authorization Header

๐ŸŽฏ Purpose

  • Authenticate and authorize API requests.

๐Ÿ’ก When to Use

  • Protected endpoints
  • User authentication

๐Ÿ“ Examples

Bearer Token

from rapidtest import HTTPTest

# Test with Bearer token
test = HTTPTest(url="http://localhost:8000")
test.get(
    path="/protected-endpoint",
    headers={"Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOi..."}
)

2. ๐Ÿ“„ Content-Type Header

๐ŸŽฏ Purpose

  • Specify the format of request/response body.

๐Ÿ’ก When to Use

  • Sending JSON data
  • Form submissions
  • File uploads

๐Ÿ“ Examples

JSON Data

# Sending JSON data
data = {"name": "John", "email": "john@example.com"}
test.post(
    path="/users",
    json=data,  # RapidTest automatically sets Content-Type: application/json
    headers={"Content-Type": "application/json"}
)

๐ŸŽฏ Purpose

  • Manage session state and user preferences.

๐Ÿ’ก When to Use

  • Session management
  • User preferences
  • Authentication tokens

๐Ÿ“ Examples

Sending Cookies

# Test with session cookie
test.get(
    path="/dashboard",
    headers={
        "Cookie": "session_id=abc123; user_pref=dark_mode"
    }
)

๐Ÿงช Testing Headers with RapidTest

RapidTest makes testing HTTP headers incredibly simple with its intuitive syntax. You can easily verify both request headers and response headers. โœจ

๐ŸŽฏ What's Next?