Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All the responses should follow the best practice structure #2

Open
agentmilindu opened this issue Jan 13, 2019 · 2 comments
Open

All the responses should follow the best practice structure #2

agentmilindu opened this issue Jan 13, 2019 · 2 comments
Assignees

Comments

@agentmilindu
Copy link
Member

Usually, the JSON responses sent from RESTful services have a common structure to follow,

{
   "data" : { 
     "someprop" : "somevalue",
     ....
   },
   "error" : [ ] 
}

Or

{
   "data" : {},
   "error" : [ 
     {
        "code" : "4000",
        "message" : "User not authorized"
     }
   ] 
}

Shall we follow the same?

@iamchathu
Copy link
Collaborator

Let's have errors like it but with ERROR status code in http status

Eg

422 for Unprocessable Entity etc...

But let's keep 200 for data and send data directly.

What's you idea @agentmilindu

@agentmilindu
Copy link
Member Author

yeah, the HTTP error code should follow the proper HTTP codes. The code in our error object can be extensible. For example, we can have several reasons to be sending HTTP 400 for an endpoint and we can have codes like "4000", "4001", "4002", etc for these several reasons. Then we can easily track, categorize, etc with these codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants