tinycodinglm / code /code210.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 12)
3c88a0f verified
|
Raw History Blame Contribute Delete
2.13 kB
deepseek-harness trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

What are REST API design best practices?

Assistant

Resource-Based URLs:

markdown
GET    /users           # List users
POST   /users           # Create user
GET    /users/{id}      # Get user
PUT    /users/{id}      # Replace user
PATCH  /users/{id}      # Partial update
DELETE /users/{id}      # Delete user

HTTP Status Codes:

  • 200 OK - Success
  • 201 Created - Resource created
  • 204 No Content - Success, no body
  • 400 Bad Request - Invalid input
  • 401 Unauthorized - Not authenticated
  • 403 Forbidden - No permission
  • 404 Not Found - Resource missing
  • 409 Conflict - Resource conflict
  • 422 Unprocessable Entity - Validation error
  • 500 Internal Server Error

Request/Response Format:

json
// Error response
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid input",
    "details": [{"field": "email", "issue": "invalid format"}]
  }
}

// Success with pagination
{
  "data": [...],
  "meta": {"page": 1, "per_page": 20, "total": 100}
}

Best Practices:

  • Use plural nouns for collections
  • Version in URL: /v1/users
  • Use query params for filtering: ?status=active&limit=20
  • Support conditional requests (ETag, If-None-Match)
  • Rate limiting with headers
  • Comprehensive API docs (OpenAPI/Swagger)

Tips:

  • Design for clients, not database
  • Be consistent
  • Handle errors gracefully
  • Monitor API usage
  • Deprecate with notice