-
Notifications
You must be signed in to change notification settings - Fork 35
Description
I want to understand the best practices that we need to consider while designing API responses.
Problem Statement
Let's assume I have an endpoint /v1/projects/all which return the list of projects and its response look something like this
{
"projects": [{
"id": "001",
"name": "test nw UPM member",
"isPublic": false,
"isShared": false,
}, {
"id": "002",
"name": "move test",
"isPublic": false,
"isShared": true,
}]
}
Notice the isShared flag indicates if the project is shared with other users. If it is
true - It means the project is shared with another user
false - It means the project is not shared with another user
Now I have another API that only gives me the list of shared projects
The endpoint looks something like this /v1/projects/shared-by-me The response of that looks like below
{
"projects": [{
"id": "002",
"name": "move test",
"isPublic": false,
}]
}
Note: I do not pass isShared flag here since the endpoint itself indicates that projects are shared by me meaning isShared will be always true in that case.
Question
What according to best practices should the response be like? Should I include the isShared property in /v1/projects/shared-by-me or it's ok to not include that?
Client Side Implementation
Assume client-side has a common react component that renders the details based on this response. so If I don't pass isShared it is recommended for the Client-side to add it manually and add conditional rendering?