Every day we come across several APIs knowingly or unknowingly, as an engineer its are our responsibility to design API endpoints efficiently to make the world a lot easier for other fellow developers and end-users. API design tips and tricks
Here we will discuss few important tips one should keep in mind while creating API endpoints.
1. Give a proper name
Make sure the name you give to your API meaningful. I would suggest it be what it does like a verb.
Example – If you return sum of 2 numbers name it getSum, if the API calculates tax you can name it calculateTax().
2. Should solve only one particular problem.
An API should always one particular problem. Never mix the functionality with too many actions. Try to segregate the solutions if is happens the problem need to be solved in multiple steps.
For example – If you are trying to read inputs from a user form you do it in 2 steps, one to validate the inputs and another to store them. In this way, you segregate the functionality and in the future, it will be easy to add any more validation if necessary without breaking the code related to storing.
3. Do a proper research while designing the API
It is very important to know the audience for our endpoint. Pick up the development only you have completely understood the requirements. It is really a bad idea to change the endpoints once they are being used by the consumers.
4. Create a new endpoint in of a new requirement
It is often relatable to the fact the requirement keeps on changing and a good idea to keep the code backwards compatible and open for enhancements. Deprecate only when no longer being used. To suit a similar requirement instead of modifying the existing provide a new endpoint whole together.
5. Keep the endpoints as independent as possible.
Always keep in mind the endpoints should be independent in order to achieve maintainability. Also, it will be helpful to test them as an independent block rather than depend on some other functionality to work as expected.
6. Always return proper message.
Keep the user with the knowledge of whats happening behind the scenes with proper messages, give enough information in case of a failure. Messages are helpful the user/developer to debug through in case of a failure.
These are things to keep in mind which you should never do while designing an API.
1. Do not expose the implementation details to user.
Never expose the implications to user be it though the messages or though the code directly. Make use interface and abstract classes.
2. Never forget to provide documentation.
Provide a very handy and comprehensive documentation about your API and what problem it is solving. Make sure they explain very well and do not lead to confusion.
3. Never push incomplete.
Never commit changes that are breaking or incomplete, which might to confusion among fellow developers. Commit in a state which can be taking forward in a health manner with minimal explanations.
And also if you require any technology you want to learn, let us know below we will publish them on our site http://tossolution.com/
Like our page in Facebook and follow us for New technical information.
API design tips and tricks