4. Working with APIs
1. How to work with an API?
So far we have learnt what requests and responses are. We also learnt about endpoints, query parameters and body data.
To get started with any API, you need to do the following âž–
- Read the API documentation carefully.
- Find which endpoints which matches your business need.
- Check whether there is any authentication/authorisation required to access the API.
- Test the API through Postman or by curl request.
- Implement via code
2. Exploring an API documentation
Let's say you want to integrate Google signup API on your website (i.e. you want that your users can signup using their Google account)
What would be the first step? The first step would be to read the APIs documentation.
API documentation always the starting point when it comes to working with APIs.
Remember! A good API should have detailed documentation explaining how to work with it.
- It should describe the basics - what the API does, what type of data you can get from it?
- It should explain the requirements for using the API. Is it free or paid? Does it require you to register and obtain a key?
- It should also provide examples of how to make requests and the responses returned.
- And most importantly, for actually working with the API, it should provide you with endpoints and parameters.
Note - API Documentation is also called API contract.
Checkout sample API documentation - https://drive.google.com/file/d/1F3IKpbYee2MClDhZ1-BdUGXnE_9UmgCz/view?usp=sharing
3. Working with the Github API
Problem Statement: Show the profile information of a user based on the GitHub username.
It is highly recommended to do it yourself first (on your own)
Let's get started according to our checklist.
- Find the official API documentation
- Find the API endpoint which matches your problem statement.
- Test the API request using curl or postman.
Solution
API Link - https://docs.github.com/en/rest/guides/getting-started-with-the-rest-api
Make a curl request
curl -i https://api.github.com/users/dipakkr
4. Sample API documentation
Here are a few examples of the best API documentation you can read and play around with.
- Stripe - https://stripe.com/docs/api
- Notion - https://developers.notion.com/
- SendGrid - https://sendgrid.com/solutions/email-api/
- Github - https://docs.github.com/en/rest