Following is one of the current issues in ScholarX Backend
I decided to do a bit research before working on the issue because it’s necessary to carry out a consistent REST architecture through out all our platforms. Following are few of my findings,
If data owner is unavailable
A 404
response is suited.
Eg: When an Admin is trying to update a specific program and the ID is unavailable, When a mentor requests his/her mentees with an unavailable mentor ID, etc.
According to rfc2616 404 represent,
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.
Since the program ID is part of the URI this response is suited.
If the data(program/mentor/etc.) is in an invalid state
A 400
response is suited.
According to rfc2616 400 represent,
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
In this case malformed syntax is the invalid state. So this response is suited.
If the data is valid but currently unavailable
Either a 204
with no data or 200
with empty object(List, Mentor, etc.) is suited.
According to rfc2616 204 represent,
The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.
According to rfc2616 200 represent,
The request has succeeded. The information returned with the response is dependent on the method used in the request, for example:
GET an entity corresponding to the requested resource is sent in the response;
Both these approaches are fine. But the approach should be consistent and should be chosen depending on the user client(REACT app).
End
Currently we are following most of the above approaches. But I felt the need to clarify and document this problem. What is your idea on above suggestions: did I miss anything? should we use different responses?
cc: @EngTeam