Skip to content
v1.0.0

Example of an OpenAPI document with security​

OpenAPI security examples backed by httpbin.io so the playground returns real responses (headers, bearer auth, cookies, request body echo).

Servers​

https://httpbin.iohttpbin.io — HTTP request & response testing service

API key in header​

GET
/anything/only-api-key

Calls httpbin /anything, which echoes request headers so you can verify api_key was sent.

Authorizations​

apiKey
Type
API Key (header: api_key)
Example"your-api-key"

Responses​

Echo of the request including headers

application/json

Playground​

Authorization

Samples​


Bearer authentication​

GET
/bearer

Calls httpbin /bearer, which requires a valid Authorization: Bearer <token> header and returns 401 without it.

Authorizations​

bearerAuth
Type
HTTP (bearer)
Example"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30"

Responses​

Authenticated

application/json

Playground​

Authorization

Samples​


API key and bearer auth​

PUT
/put

Calls httpbin /put, which echoes headers and JSON body. Requires both api_key and bearer auth.

Authorizations​

apiKey
Type
API Key (header: api_key)
Example"your-api-key"
+
bearerAuth
Type
HTTP (bearer)
Example"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30"

Parameters​

Header Parameters

headerParam*

Header parameter description

Type
string
Required
Example"value"

Responses​

Echo of the PUT request

application/json

Playground​

Authorization
Headers

Samples​


API key or bearer auth​

GET
/anything/{pathParam}

Calls httpbin /anything/{pathParam}. Accepts either an API key or a bearer token.

Authorizations​

apiKey
Type
API Key (header: api_key)
Example"your-api-key"
or
bearerAuth
Type
HTTP (bearer)
Example"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30"

Parameters​

Path Parameters

pathParam*

Path segment echoed by httpbin

Type
string
Required
Example"demo"

Responses​

Echo of the request

application/json

Playground​

Authorization
Variables
Key
Value

Samples​


Multiple security requirement options​

POST
/anything/{pathParam}

Calls httpbin /anything/{pathParam} with a JSON body. Either (apiKey + bearer) or (basicAuth + internalApiKey).

Authorizations​

apiKey|bearerAuth
apiKey
Type
API Key (header: api_key)
Example"your-api-key"
+
bearerAuth
Type
HTTP (bearer)
Example"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30"
or
basicAuth|internalApiKey
basicAuth

Basic authentication with username and password

Type
HTTP (basic)
+
internalApiKey

Internal API key for special customers

Type
API Key (header: internal_api_key)
Example"special-key"

Parameters​

Path Parameters

pathParam*

Path segment echoed by httpbin

Type
string
Required
Example"demo"

Query Parameters

param1*

Query parameter description

Type
string
Required
Valid values
"value1""value2"
Default
"value1"
param2*

Another query parameter description

Type
string
Required
Example"hello"

Request Body​

application/json

Responses​

Echo of the request including body, args, and headers

application/json

Playground​

Authorization
Variables
Key
Value
Body

Samples​


No security​

GET
/get

Calls httpbin /get with no authentication required.

Responses​

Echo of the GET request

application/json

Playground​

Samples​


API key in query​

GET
/anything/api-key-query

Calls httpbin /anything, which echoes query args so you can verify api_key was sent as a query parameter.

Authorizations​

apiKeyQuery
Type
API Key (query: api_key)
Example"your-api-key"

Parameters​

Query Parameters

optionalParam

An optional query parameter

Type
string
Example"optional-value"

Responses​

Echo of the request including query args

application/json

Playground​

Authorization
Variables
Key
Value

Samples​


apiKey header name differs from scheme key​

GET
/headers

Uses managementKey as the securitySchemes key but sends the header X-Management-Key. Code samples must use the scheme name, not the key. Calls httpbin /headers so the response shows the received headers.

Authorizations​

managementKey

Management API key. Scheme key is managementKey; header name is X-Management-Key.

Type
API Key (header: X-Management-Key)
Example"mgmt-secret"

Responses​

Request headers as seen by httpbin

application/json

Playground​

Authorization

Samples​


apiKey in cookie​

GET
/cookies

Uses an apiKey scheme with in: cookie. Code samples must send a Cookie request header, not Set-Cookie. Calls httpbin /cookies, which returns cookies received on the request.

Authorizations​

sid

Session id cookie. Request samples must use the Cookie header.

Type
API Key (cookie: SID)
Example"session-id-example"

Responses​

Cookies received by httpbin

application/json

Playground​

Authorization

Samples​


Powered by VitePress OpenAPI