DEV Community

Discussion on: Designing APIs for humans: Design patterns

Collapse
 
ajitzero profile image
Ajit Panigrahi

On the last example, I believe a PUT call should respond with an error status for missing fields, and for partial changes we should use PATCH instead. But considering your point to be intuitive, I would say we should send an optional suggestion field in the PUT case but still cause it to error out. e.g.:

{
   // Some internal error code for tracking
  "code":  "MISSING_REQUIRED_FIELDS", // or: -1

  // can be used for showing error message in UI.
  "message": "Required fields: 'name', 'email'.",

   // can be hidden from UI but REST API users can see the help text.
  "suggestion": "Use PATCH for partial updates."
}
Enter fullscreen mode Exit fullscreen mode

Intuition should not break conventions.