0

For a successful RESTful HTTP request, we can return an object that is serialized.

But in case of an error, for example when a resource is not found (404), should this return a HTTP response with error code 404, or can it alternatively return an object which has a custom error information in it?

Bogdan
  • 23,890
  • 3
  • 69
  • 61
AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140

1 Answers1

1

...for example when a resource is not found (404), should this return a HTTP response with error code 404, or can it alternatively return an object which has a custom error information in it?

You can do both.

A 404 is a resource not found and your response status code should be 404. If you want to give additional information or have a special error object with particular codes in it then return that too as part of the body.

Also have a look at this post: REST API error return good practices

Community
  • 1
  • 1
Bogdan
  • 23,890
  • 3
  • 69
  • 61