restfulapi / api-strategy Goto Github PK
View Code? Open in Web Editor NEWAPI strategy for RESTful APIs
API strategy for RESTful APIs
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.