json - REST API error return, include HTTP status code or not -


i'm working on restful api end, , use json content type. , there 2 ways of performing error response know:

  1. http status code 200, , returning json should contain error code , error message.
  2. treat http status code part of our api, may pick http error code(4xx) corresponding error condition. , can include json document in payload includes sub-code , descriptive comment.

i want know 1 more idiom restful service?

generally speaking, not advocate returning 200. there failure scenarios match commonly accepted status codes. above, mentioned 403, deliver when access denied. , 500 typically issued web/app server when things go south. , 404 if either record not found resource.

so, advocate for:

  1. going @ least 200, 403, 404, 500
  2. providing verbose error details possible in json error response
  3. documenting every error code api might deliver - http status codes , every sub-condition error

Comments