|
1 | 1 | --- |
2 | 2 | title: 'MDX Setup' |
3 | | -description: 'Generate docs pages for your API endpoints using MDX' |
| 3 | +description: 'Learn how to create API documentation using MDX' |
4 | 4 | --- |
5 | 5 |
|
6 | | -Mintlify allows you to define your API endpoints using a combination of `docs.json` configuration, MDX metadata fields, and the `<ParamFields />` component. From the defined endpoints, we generate an API playground, request examples, and response examples. |
| 6 | +Mintlify helps you create beautiful API documentation using MDX (Markdown + JSX). This guide will show you how to set up your API endpoints step by step. |
| 7 | + |
| 8 | +## Basic Setup |
| 9 | + |
| 10 | +Let's start with the simplest configuration possible: |
7 | 11 |
|
8 | 12 | <Steps> |
9 | | - <Step title="Configure your API"> |
10 | | - In your `docs.json` file, define your base URL and auth method: |
| 13 | + <Step title="Create an API endpoint page"> |
| 14 | + Create a new MDX file for your API endpoint. At the top, add these basic details: |
| 15 | + |
| 16 | + ```md |
| 17 | + --- |
| 18 | + title: 'List All Users' |
| 19 | + api: 'GET /users' |
| 20 | + --- |
| 21 | + ``` |
| 22 | + |
| 23 | + That's all you need to get started! This will create a basic API documentation page. |
| 24 | + </Step> |
| 25 | + |
| 26 | + <Step title="Add it to your navigation"> |
| 27 | + Add your new page to the `navigation` section in your `docs.json` file: |
11 | 28 |
|
12 | 29 | ```json |
13 | | - "api": { |
14 | | - "mdx": { |
15 | | - "server": "https://mintlify.com/api", // string array for multiple base URLs |
16 | | - "auth": { |
17 | | - "method": "key", |
18 | | - "name": "x-api-key" // options: bearer, basic, key. |
| 30 | + { |
| 31 | + "navigation": [ |
| 32 | + { |
| 33 | + "group": "API Reference", |
| 34 | + "pages": ["api-reference/list-users"] |
19 | 35 | } |
20 | | - } |
| 36 | + ] |
21 | 37 | } |
22 | 38 | ``` |
| 39 | + </Step> |
| 40 | +</Steps> |
23 | 41 |
|
24 | | - If you would not like to show an API playground, you don't need to include auth types. Hide the playground with the following field: |
| 42 | +## Advanced Configuration |
25 | 43 |
|
26 | | - ```json |
27 | | - "api": { |
28 | | - "playground": { |
29 | | - "display": "none" |
| 44 | +Once you're comfortable with the basics, you can add more features to your API documentation. |
| 45 | + |
| 46 | +### Setting Up Your API Configuration |
| 47 | + |
| 48 | +In your `docs.json` file, you can define global settings for all your API endpoints: |
| 49 | + |
| 50 | +<CodeGroup> |
| 51 | +```json Basic Configuration |
| 52 | +{ |
| 53 | + "api": { |
| 54 | + "mdx": { |
| 55 | + "server": "https://api.example.com" |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +```json Multiple Base URLs |
| 62 | +{ |
| 63 | + "api": { |
| 64 | + "mdx": { |
| 65 | + "server": [ |
| 66 | + "https://api.example.com", |
| 67 | + "https://api-staging.example.com" |
| 68 | + ] |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +``` |
| 73 | +</CodeGroup> |
| 74 | + |
| 75 | +### Adding Authentication |
| 76 | + |
| 77 | +<Note> |
| 78 | + Authentication settings let your users test API endpoints with their own API keys. |
| 79 | +</Note> |
| 80 | + |
| 81 | +Add authentication settings to your `docs.json`: |
| 82 | + |
| 83 | +```json |
| 84 | +{ |
| 85 | + "api": { |
| 86 | + "mdx": { |
| 87 | + "server": "https://api.example.com", |
| 88 | + "auth": { |
| 89 | + "method": "key", |
| 90 | + "name": "x-api-key" |
30 | 91 | } |
31 | 92 | } |
32 | | - ``` |
33 | | - |
34 | | - Find a full list of API configurations [here](/core-concepts/settings#param-api). |
35 | | - </Step> |
36 | | - |
37 | | - <Step title="Create your endpoint pages"> |
| 93 | + } |
| 94 | +} |
| 95 | +``` |
38 | 96 |
|
39 | | - Each API endpoint page should have a corresponding MDX file. At the top of each file, define: |
| 97 | +### Path Parameters |
40 | 98 |
|
41 | | - ```md |
42 | | - --- |
43 | | - title: 'Create new user' |
44 | | - api: 'POST https://api.mintlify.com/user' |
45 | | - --- |
46 | | - ``` |
| 99 | +You can include path parameters in your API endpoints using curly braces: |
47 | 100 |
|
48 | | - You can specify path parameters by adding the parameter name to the path, wrapped with `{}`: |
| 101 | +```md |
| 102 | +--- |
| 103 | +title: 'Get User Details' |
| 104 | +api: 'GET /users/{userId}' |
| 105 | +--- |
| 106 | +``` |
49 | 107 |
|
50 | | - ```bash |
51 | | - https://api.example.com/v1/endpoint/{userId} |
52 | | - ``` |
| 108 | +<Tip> |
| 109 | + When you have `server` configured in docs.json, you can use shorter paths like `/users` instead of full URLs. |
| 110 | +</Tip> |
53 | 111 |
|
54 | | - <Note> |
| 112 | +### Customizing the API Playground |
55 | 113 |
|
56 | | - If you have `server` configured in [docs.json](/core-concepts/settings), you can use relative paths like `/v1/endpoint`. |
| 114 | +The API playground lets users test your endpoints directly in the documentation. You can control its display: |
57 | 115 |
|
58 | | - </Note> |
| 116 | +<CodeGroup> |
| 117 | +```json Hide Playground Everywhere |
| 118 | +{ |
| 119 | + "api": { |
| 120 | + "playground": { |
| 121 | + "display": "none" |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
59 | 126 |
|
60 | | - You can also override the globally-defined display mode for the API playground per page by adding `playground` at the top of the MDX file: |
| 127 | +```md Hide Playground on One Page |
| 128 | +--- |
| 129 | +title: 'Create User' |
| 130 | +api: 'POST /users' |
| 131 | +playground: 'none' |
| 132 | +--- |
| 133 | +``` |
| 134 | +</CodeGroup> |
61 | 135 |
|
62 | | - ```md |
63 | | - --- |
64 | | - title: 'Create new user' |
65 | | - api: 'POST https://api.mintlify.com/user' |
66 | | - playground: 'none' |
67 | | - ``` |
68 | | - |
69 | | - </Step> |
| 136 | +## Next Steps |
70 | 137 |
|
71 | | - <Step title="Add your endpoints to your docs"> |
72 | | - Add your endpoint pages to the sidebar by adding the paths to the `navigation` field in your `docs.json`. Learn more about structuring your docs [here](/core-concepts/navigation). |
73 | | - </Step> |
74 | | -</Steps> |
| 138 | +- Learn more about [authentication options](/api-playground/mdx/authentication) |
| 139 | +- Explore [advanced API configurations](/core-concepts/settings#param-api) |
| 140 | +- See how to [structure your documentation](/core-concepts/navigation) |
0 commit comments