بنقرة واحدة
api-design
RESTful API design patterns, HTTP standards, versioning, error handling, and documentation
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
RESTful API design patterns, HTTP standards, versioning, error handling, and documentation
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Joomla 4/5 component development with MVC, services, plugins, and language handling
Joomla 3.x legacy patterns with JFactory, non-namespaced MVC, JDatabase, and plugin structure
Laravel best practices for Eloquent, controllers, validation, services, and testing
Performance optimization for PHP, JavaScript, databases, and caching strategies
PHP coding standards including strict typing, OOP patterns, error handling, and documentation
Deep dive into SOLID principles with PHP/TypeScript examples, refactoring patterns, and violation detection
| name | api-design |
| description | RESTful API design patterns, HTTP standards, versioning, error handling, and documentation |
| license | MIT |
| compatibility | opencode |
| metadata | {"type":"architectural","protocols":"rest, http"} |
# Good - nouns, plural, hierarchical
GET /api/v1/users
GET /api/v1/users/{id}
GET /api/v1/users/{id}/posts
POST /api/v1/users
PUT /api/v1/users/{id}
PATCH /api/v1/users/{id}
DELETE /api/v1/users/{id}
# Bad
GET /api/v1/getUsers
POST /api/v1/createUser
GET /api/v1/user/list
| Method | Purpose | Idempotent | Safe |
|---|---|---|---|
| GET | Retrieve resource | Yes | Yes |
| POST | Create resource | No | No |
| PUT | Replace resource | Yes | No |
| PATCH | Partial update | No | No |
| DELETE | Remove resource | Yes | No |
| Code | Use Case |
|---|---|
| 200 | OK - GET, PUT, PATCH success |
| 201 | Created - POST success, include Location header |
| 204 | No Content - DELETE success |
| Code | Use Case |
|---|---|
| 400 | Bad Request - malformed syntax |
| 401 | Unauthorized - authentication required |
| 403 | Forbidden - authenticated but not allowed |
| 404 | Not Found - resource doesn't exist |
| 409 | Conflict - state conflict (duplicate, etc.) |
| 422 | Unprocessable Entity - validation failed |
| 429 | Too Many Requests - rate limited |
| Code | Use Case |
|---|---|
| 500 | Internal Server Error - unexpected failure |
| 502 | Bad Gateway - upstream service failed |
| 503 | Service Unavailable - temporarily down |
{
"data": {
"id": 123,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2024-01-15T10:30:00Z"
}
}
{
"data": [
{ "id": 1, "name": "John" },
{ "id": 2, "name": "Jane" }
],
"meta": {
"total": 100,
"page": 1,
"per_page": 20,
"last_page": 5
},
"links": {
"first": "/api/v1/users?page=1",
"last": "/api/v1/users?page=5",
"prev": null,
"next": "/api/v1/users?page=2"
}
}
{
"error": {
"code": "VALIDATION_ERROR",
"message": "The given data was invalid.",
"details": [
{
"field": "email",
"message": "The email has already been taken."
},
{
"field": "password",
"message": "The password must be at least 8 characters."
}
]
}
}
/api/v1/users
/api/v2/users
Accept: application/vnd.myapp.v1+json
/api/users?version=1
# Filtering
GET /api/v1/users?status=active&role=admin
# Sorting
GET /api/v1/users?sort=created_at&order=desc
GET /api/v1/users?sort=-created_at # Prefix minus for desc
# Pagination
GET /api/v1/users?page=2&per_page=20
# Field selection
GET /api/v1/users?fields=id,name,email
# Combining
GET /api/v1/users?status=active&sort=-created_at&page=1&per_page=10
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
X-API-Key: your-api-key
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200
Retry-After: 60
{
"data": {
"id": 123,
"name": "John Doe"
},
"links": {
"self": "/api/v1/users/123",
"posts": "/api/v1/users/123/posts",
"avatar": "/api/v1/users/123/avatar"
},
"actions": {
"update": { "method": "PUT", "href": "/api/v1/users/123" },
"delete": { "method": "DELETE", "href": "/api/v1/users/123" }
}
}
// Laravel Controller
public function index(Request $request): JsonResponse
{
$users = User::query()
->when($request->status, fn($q, $status) => $q->where('status', $status))
->when($request->sort, fn($q, $sort) => $q->orderBy($sort, $request->order ?? 'asc'))
->paginate($request->per_page ?? 20);
return UserResource::collection($users);
}
public function store(StoreUserRequest $request): JsonResponse
{
$user = User::create($request->validated());
return response()->json(
['data' => new UserResource($user)],
201,
['Location' => route('users.show', $user)]
);
}