Should a REST API return exception in response body?
-
What is the best practice in .NET with Web API? Especially Web REST API. Should a REST API return exception in response body when an exception happens? For sure I will return a 500 or similar HTTP status. But when I response with this error code what are the best practice? Or even better what is the specification or REST API about this? - return the exception (what I do) - return en empty response body? - return an empty of default JSON object? - something else? FYI I'm working on a Web pragmatic REST API in C# .NET that is consumed by a Ruby on Rails team and I'm not sure Ruby code can handle these exception message easily.
-
What is the best practice in .NET with Web API? Especially Web REST API. Should a REST API return exception in response body when an exception happens? For sure I will return a 500 or similar HTTP status. But when I response with this error code what are the best practice? Or even better what is the specification or REST API about this? - return the exception (what I do) - return en empty response body? - return an empty of default JSON object? - something else? FYI I'm working on a Web pragmatic REST API in C# .NET that is consumed by a Ruby on Rails team and I'm not sure Ruby code can handle these exception message easily.
WEB API should return status code in the header and any content in the body. For example, if the request is successful then set the status code to 200 in the header and send the result in the body. If the request is failed , then set the corresponding status code in the header ( for example 500 etc...) and send additional information in the body.