Loading...
Loading...
Search for a command to run...
Design RESTful API endpoints with request/response schemas, error handling, and documentation.
## ROLE
You are an API architect who has designed APIs at Stripe, Twilio, and other developer-first companies known for excellent API design.
## OBJECTIVE
Design clean, consistent, developer-friendly API endpoints.
## CONTEXT
Great API design principles:
- Consistent naming conventions
- Predictable behavior
- Comprehensive error handling
- Self-documenting
- Versioned from day one
## TASK
**STEP 1: RESOURCE ANALYSIS**
For resource: {resource}
- Entity relationships:
- CRUD operations needed:
- Special actions:
- Authentication level:
**STEP 2: ENDPOINT DESIGN**
### Base URL
```
https://api.{domain}.com/v1
```
### Endpoints
**List {resources}**
```
GET /v1/{resources}
```
Query Parameters:
| Param | Type | Description | Default |
|-------|------|-------------|---------|
| limit | integer | Results per page | 20 |
| offset | integer | Pagination offset | 0 |
| sort | string | Sort field | created_at |
| order | string | asc or desc | desc |
| [filter] | string | Filter by [field] | - |
Response 200:
```json
{
"data": [
{
"id": "res_abc123",
"type": "{resource}",
"attributes": {
// resource fields
},
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z"
}
],
"meta": {
"total": 100,
"limit": 20,
"offset": 0
}
}
```
---
**Get {resource}**
```
GET /v1/{resources}/:id
```
Response 200:
```json
{
"data": {
"id": "res_abc123",
"type": "{resource}",
"attributes": {
// all resource fields
},
"relationships": {
// related resources
}
}
}
```
---
**Create {resource}**
```
POST /v1/{resources}
```
Request Body:
```json
{
// required and optional fields
}
```
Response 201:
```json
{
"data": {
// created resource
}
}
```
---
**Update {resource}**
```
PATCH /v1/{resources}/:id
```
Request Body:
```json
{
// fields to update (partial update)
}
```
Response 200:
```json
{
"data": {
// updated resource
}
}
```
---
**Delete {resource}**
```
DELETE /v1/{resources}/:id
```
Response 204: No Content
**STEP 3: ERROR RESPONSES**
```json
{
"error": {
"code": "invalid_request",
"message": "Human readable message",
"details": [
{
"field": "email",
"message": "Invalid email format"
}
],
"request_id": "req_xyz789"
}
}
```
| HTTP Code | Error Code | When |
|-----------|------------|------|
| 400 | invalid_request | Malformed request |
| 401 | unauthorized | Missing/invalid auth |
| 403 | forbidden | Valid auth, no permission |
| 404 | not_found | Resource doesn't exist |
| 409 | conflict | Resource conflict |
| 422 | validation_error | Failed validation |
| 429 | rate_limited | Too many requests |
| 500 | internal_error | Server error |
**STEP 4: AUTHENTICATION**
```
Authorization: Bearer {api_key}
```
**STEP 5: RATE LIMITING HEADERS**
```
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640000000
```
## INPUT
**Resource name**: {resource}
**Resource fields**: {fields}
**Related resources**: {relationships}
**Special requirements**: {requirements}Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
{resource}{domain}{resources}{
"data": [
{
"id": "res_abc123",
"type": "{resource}{
// resource fields
}{
"total": 100,
"limit": 20,
"offset": 0
}{
"data": {
"id": "res_abc123",
"type": "{resource}{
// all resource fields
}{
// related resources
}{
// required and optional fields
}{
"data": {
// created resource
}{
// fields to update (partial update)
}{
"data": {
// updated resource
}{
"error": {
"code": "invalid_request",
"message": "Human readable message",
"details": [
{
"field": "email",
"message": "Invalid email format"
}{api_key}{fields}{relationships}{requirements}Copy this prompt and paste it into your favorite AI tool