api-docs.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // API Documentation
  2. export const API_DOCS_MD = String.raw`
  3. # REST API Documentation
  4. ## 🔐 Authentication
  5. All API requests require authentication using **Bearer tokens**. Include your API key in the Authorization header:
  6. ${'```'}http
  7. GET /api/v1/users
  8. Host: api.example.com
  9. Authorization: Bearer YOUR_API_KEY
  10. Content-Type: application/json
  11. ${'```'}
  12. ## 📍 Endpoints
  13. ### Users API
  14. #### **GET** /api/v1/users
  15. Retrieve a paginated list of users.
  16. **Query Parameters:**
  17. | Parameter | Type | Default | Description |
  18. |-----------|------|---------|-------------|
  19. | page | integer | 1 | Page number |
  20. | limit | integer | 20 | Items per page |
  21. | sort | string | "created_at" | Sort field |
  22. | order | string | "desc" | Sort order |
  23. **Response:** 200 OK
  24. ${'```'}json
  25. {
  26. "data": [
  27. {
  28. "id": "usr_1234567890",
  29. "email": "user@example.com",
  30. "name": "John Doe",
  31. "role": "admin",
  32. "created_at": "2024-01-15T10:30:00Z"
  33. }
  34. ],
  35. "pagination": {
  36. "page": 1,
  37. "limit": 20,
  38. "total": 156,
  39. "pages": 8
  40. }
  41. }
  42. ${'```'}
  43. #### **POST** /api/v1/users
  44. Create a new user account.
  45. **Request Body:**
  46. ${'```'}json
  47. {
  48. "email": "newuser@example.com",
  49. "password": "SecurePassword123!",
  50. "name": "Jane Smith",
  51. "role": "user"
  52. }
  53. ${'```'}
  54. **Response:** 201 Created
  55. ${'```'}json
  56. {
  57. "id": "usr_9876543210",
  58. "email": "newuser@example.com",
  59. "name": "Jane Smith",
  60. "role": "user",
  61. "created_at": "2024-01-21T09:15:00Z"
  62. }
  63. ${'```'}
  64. ### Error Responses
  65. The API returns errors in a consistent format:
  66. ${'```'}json
  67. {
  68. "error": {
  69. "code": "VALIDATION_ERROR",
  70. "message": "Invalid request parameters",
  71. "details": [
  72. {
  73. "field": "email",
  74. "message": "Email format is invalid"
  75. }
  76. ]
  77. }
  78. }
  79. ${'```'}
  80. ### Rate Limiting
  81. | Tier | Requests/Hour | Burst |
  82. |------|--------------|-------|
  83. | **Free** | 1,000 | 100 |
  84. | **Pro** | 10,000 | 500 |
  85. | **Enterprise** | Unlimited | - |
  86. **Headers:**
  87. - X-RateLimit-Limit
  88. - X-RateLimit-Remaining
  89. - X-RateLimit-Reset
  90. ### Webhooks
  91. Configure webhooks to receive real-time events:
  92. ${'```'}javascript
  93. // Webhook payload
  94. {
  95. "event": "user.created",
  96. "timestamp": "2024-01-21T09:15:00Z",
  97. "data": {
  98. "id": "usr_9876543210",
  99. "email": "newuser@example.com"
  100. },
  101. "signature": "sha256=abcd1234..."
  102. }
  103. ${'```'}
  104. ### SDK Examples
  105. **JavaScript/TypeScript:**
  106. ${'```'}typescript
  107. import { ApiClient } from '@example/api-sdk';
  108. const client = new ApiClient({
  109. apiKey: process.env.API_KEY
  110. });
  111. const users = await client.users.list({
  112. page: 1,
  113. limit: 20
  114. });
  115. ${'```'}
  116. **Python:**
  117. ${'```'}python
  118. from example_api import Client
  119. client = Client(api_key=os.environ['API_KEY'])
  120. users = client.users.list(page=1, limit=20)
  121. ${'```'}
  122. ---
  123. 📚 [Full API Reference](https://api.example.com/docs) | 💬 [Support](https://support.example.com)
  124. `;