Sunday, January 11, 2015

What is the right way to define REST API

Approach One: Return 200 Status Code for Application Error Message
1. Define a standard RESTResponse object, which encapsulate all the application error message and return to UI. All the error will return 200 status code. Then UI will translate the error message and display it properly to UI.

Approach Two: Return 500 Status Code for Application Error Message
1. For application error message, throw an exception and return 500 status code.
2. Return the real JSON object back to UI, and let UI handle http status code.
3. This is the standard approach.

Best Practice:
1. Use the right URL Path
2. Use path variable instead of parameters
3. Use proper Error Response with Http Status Code and Error Message.
4.







No comments:

Post a Comment