|
| 1 | +--- |
| 2 | +title: 'Runnable Endpoint' |
| 3 | +description: 'Test API endpoints directly from your documentation with an interactive request builder.' |
| 4 | +--- |
| 5 | + |
| 6 | +Runnable Endpoint is an interactive component that allows users to test API endpoints directly within your documentation. It provides a full-featured request builder with form inputs for headers, path parameters, query parameters, and request bodies, along with real-time response preview. |
| 7 | + |
| 8 | +## Basic Usage |
| 9 | + |
| 10 | +The Runnable Endpoint component automatically detects and loads endpoint definitions from your API specification. You can embed it in your documentation pages using the `<RunnableEndpoint>` component. |
| 11 | + |
| 12 | +<Tabs> |
| 13 | +<Tab title="Example"> |
| 14 | +```jsx |
| 15 | +<RunnableEndpoint endpoint="POST /api/users" /> |
| 16 | +``` |
| 17 | +</Tab> |
| 18 | +<Tab title="Markdown"> |
| 19 | +````markdown |
| 20 | +<RunnableEndpoint endpoint="POST /api/users" /> |
| 21 | +```` |
| 22 | +</Tab> |
| 23 | +</Tabs> |
| 24 | + |
| 25 | +## Features |
| 26 | + |
| 27 | +### Interactive Form Builder |
| 28 | + |
| 29 | +The component automatically generates input forms based on your endpoint definition, including: |
| 30 | + |
| 31 | +- **Headers**: Add and configure request headers |
| 32 | +- **Path Parameters**: Fill in dynamic URL segments |
| 33 | +- **Query Parameters**: Add URL query string parameters |
| 34 | +- **Request Body**: Edit JSON request payloads |
| 35 | + |
| 36 | +All fields are collapsible for a cleaner interface when working with endpoints that have many parameters. |
| 37 | + |
| 38 | +### Multiple Examples Support |
| 39 | + |
| 40 | +When your endpoint has multiple pre-configured examples, the Runnable Endpoint component displays a dropdown selector in the header, allowing users to quickly switch between different example scenarios. |
| 41 | + |
| 42 | +<Frame> |
| 43 | + |
| 44 | +</Frame> |
| 45 | + |
| 46 | +### Environment Selection |
| 47 | + |
| 48 | +If your API defines multiple environments (production, staging, development), the component automatically displays an environment selector, making it easy for users to test against different base URLs. |
| 49 | + |
| 50 | +### Request Execution |
| 51 | + |
| 52 | +Users can send real HTTP requests to your API directly from the documentation. The component handles: |
| 53 | + |
| 54 | +- Request construction with proper headers and authentication |
| 55 | +- Real-time request/response preview |
| 56 | +- Error handling and display |
| 57 | +- Response status codes and timing |
| 58 | + |
| 59 | +### Link to API Reference |
| 60 | + |
| 61 | +The component includes an "Open in API reference" button that navigates users to the full API reference page for the endpoint, providing quick access to detailed documentation. |
| 62 | + |
| 63 | +### Form State Persistence |
| 64 | + |
| 65 | +Form inputs are automatically persisted in the browser's local storage, so users' test data is preserved even when navigating between pages or refreshing the browser. |
| 66 | + |
| 67 | +## Properties |
| 68 | + |
| 69 | +<ParamField path="endpoint" type="string" required={false}> |
| 70 | + The endpoint locator in the format "METHOD /path". For example: `"POST /api/users"` or `"GET /api/users/{id}"`. |
| 71 | +</ParamField> |
| 72 | + |
| 73 | +<ParamField path="example" type="string" required={false}> |
| 74 | + Pre-fill the form with a specific example by name. If not specified, the first example is used by default. |
| 75 | +</ParamField> |
| 76 | + |
| 77 | +<ParamField path="className" type="string" required={false}> |
| 78 | + Optional CSS class name for custom styling of the component container. |
| 79 | +</ParamField> |
| 80 | + |
| 81 | +## Architecture |
| 82 | + |
| 83 | +The Runnable Endpoint component is built with a modular architecture: |
| 84 | + |
| 85 | +- **RunnableEndpointHeader**: Displays the endpoint URL, method, example selector, and navigation controls |
| 86 | +- **RunnableEndpointFormSection**: Renders input forms for different parameter types (headers, path, query, body) |
| 87 | +- **RunnableEndpointActions**: Provides action buttons for clearing the form and sending requests |
| 88 | +- **RunnableEndpointResponseSection**: Displays the API response with syntax highlighting and formatting |
| 89 | + |
| 90 | +This componentized structure makes the code easier to maintain and allows for future enhancements to individual sections without affecting others. |
| 91 | + |
| 92 | +## Example with Custom Configuration |
| 93 | + |
| 94 | +<Tabs> |
| 95 | +<Tab title="Example"> |
| 96 | +```jsx |
| 97 | +<RunnableEndpoint |
| 98 | + endpoint="POST /api/users" |
| 99 | + example="Create Admin User" |
| 100 | + className="my-custom-runnable" |
| 101 | +/> |
| 102 | +``` |
| 103 | +</Tab> |
| 104 | +<Tab title="Markdown"> |
| 105 | +````markdown |
| 106 | +<RunnableEndpoint |
| 107 | + endpoint="POST /api/users" |
| 108 | + example="Create Admin User" |
| 109 | + className="my-custom-runnable" |
| 110 | +/> |
| 111 | +```` |
| 112 | +</Tab> |
| 113 | +</Tabs> |
| 114 | + |
| 115 | +## Best Practices |
| 116 | + |
| 117 | +1. **Use descriptive examples**: When defining multiple examples in your API specification, use clear, descriptive names that help users understand what each example demonstrates. |
| 118 | + |
| 119 | +2. **Include authentication details**: Make sure to document any required authentication headers or tokens that users need to provide to successfully test endpoints. |
| 120 | + |
| 121 | +3. **Provide meaningful example data**: Pre-populate examples with realistic data that demonstrates the full capabilities of your API. |
| 122 | + |
| 123 | +4. **Test in multiple environments**: If you offer staging and production environments, make sure both are properly configured so users can safely test without affecting production data. |
| 124 | + |
| 125 | +5. **Document expected responses**: While the component shows real responses, it's helpful to document what users should expect to see for successful requests. |
0 commit comments