OpenAPI
Test API endpoints directly from documentation with the Try It modal
Docs Kit's OpenAPI integration includes interactive features that let users test API endpoints directly from the documentation without leaving the browser.
Every API endpoint page includes a "Try It" button that opens an interactive modal for testing the endpoint.
The Try It modal automatically generates input fields for all parameters:
GET /api/users/{id}
Input field: id (marked as required if specified in spec)
GET /api/users?role=admin&limit=10
Input fields for each query parameter with:
X-Custom-Header: value
Accept-Language: en-US
Input fields for custom headers required by the endpoint.
For POST/PUT/PATCH endpoints, choose between two input modes:
Schema-based form with fields for each property:
{
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"subscribed": true
}
Generates form fields:
name (string)email (string with email format)age (number)subscribed (boolean)Direct JSON editing for complex structures:
{
"name": "John Doe",
"email": "john@example.com",
"metadata": {
"source": "web",
"campaign": "spring-2024"
},
"tags": ["vip", "newsletter"]
}
Toggle between modes with the "Form" / "Raw JSON" tabs.
The Try It modal automatically detects authentication requirements from your OpenAPI spec and provides appropriate input fields.
Header-based:
X-API-Key: your_api_key_here
Query-based:
?api_key=your_api_key_here
Cookie-based:
Cookie: api_key=your_api_key_here
Authorization: Bearer eyJhbGc...
Common for JWT tokens and OAuth 2.0.
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Enter username and password, auto-encoded to Base64.
Support for OAuth 2.0 flows:
Authentication values are stored in browser localStorage and persist across page reloads.
When the request succeeds:
Status: 200 OK
Content-Type: application/json
{
"success": true,
"data": {
"id": "123",
"name": "John Doe",
"email": "john@example.com"
}
}
Displayed with:
When the request fails:
Status: 400 Bad Request
Content-Type: application/json
{
"error": {
"code": "invalid_request",
"message": "Email is required"
}
}
Displayed with:
See the exact request being sent:
cURL:
curl -X POST https://api.example.com/users \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com"}'
Request Body:
{
"name": "John Doe",
"email": "john@example.com"
}
Request Headers:
Authorization: Bearer TOKEN
Content-Type: application/json
User-Agent: DocsKit/1.0
Generate code examples in multiple languages based on the current request:
const response = await fetch('https://api.example.com/users', {
method: 'POST',
headers: {
'Authorization': 'Bearer TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'John Doe',
email: 'john@example.com'
})
});
const data = await response.json();import requests
response = requests.post(
'https://api.example.com/users',
headers={
'Authorization': 'Bearer TOKEN',
'Content-Type': 'application/json'
},
json={
'name': 'John Doe',
'email': 'john@example.com'
}
)
data = response.json()curl -X POST https://api.example.com/users \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type": application/json" \
-d '{"name":"John Doe","email":"john@example.com"}'$response = Http::withToken('TOKEN')
->post('https://api.example.com/users', [
'name' => 'John Doe',
'email' => 'john@example.com'
]);
$data = $response->json();Code snippets update dynamically as you modify parameters and request body.
The Try It modal uses the base URL from your OpenAPI spec:
{
"servers": [
{
"url": "https://api.example.com",
"description": "Production"
},
{
"url": "https://api.sandbox.example.com",
"description": "Sandbox"
}
]
}
If multiple servers are defined, users can select which environment to use.
For the Try It feature to work, your API must:
Access-Control-Allow-Origin: https://docs.example.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH
Access-Control-Allow-Headers: Authorization, Content-Type
If users see CORS errors in the Try It modal, your API needs to whitelist your documentation domain in its CORS configuration.
In your OpenAPI spec, include examples:
{
"components": {
"schemas": {
"User": {
"properties": {
"name": {
"type": "string",
"example": "John Doe"
},
"email": {
"type": "string",
"format": "email",
"example": "john@example.com"
}
}
}
}
}
}
Examples auto-populate the Try It modal for easier testing.
Use a sandbox/test environment as the default server:
{
"servers": [
{
"url": "https://api.sandbox.example.com",
"description": "Sandbox (recommended for testing)"
},
{
"url": "https://api.example.com",
"description": "Production"
}
]
}
{
"parameters": [
{
"name": "limit",
"in": "query",
"description": "Number of results to return (1-100). Default: 10",
"schema": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"default": 10
}
}
]
}
Descriptions appear as helper text in the Try It modal.
Finally, learn how to configure Authentication for your API endpoints.