Learning basics of APIs from scratch and sending in your first request.
I worked on public APIs for the first time as a part of an office task. I have shared my learnings from various platforms combined here. Who is this for ? - Absolute beginners who are trying to send in their first API request.
What is an API ?
API is Application programming interface, an interface between two software applications. APIs act as a bridge between applications to share information.
You order food and get it back from the kitchen through your waiter. Waiter is the API here. A simple real-world example is Google Maps API which is a public API that makes integrating Maps into your application easy, you can access the data they provide publicly through maps API.
API key and types of requests :
There are 5 main API requests to query database the way you want. - GET, POST , PUT , DELETE & PATCH. I only used GET for my task. GET as the name suggests is used to retrieve data from the database. For my application I used an public API that could randomly get you motivational quotes from it's database after sending in the GET request. POST is used to add a new resource to the database. It will create a new resource and also its ID- URI . Put - to modify existing resources using their resource ID - resource URI .
API keys are unique to each project as its identifier. Main purpose is to authenticate the user, associate it with a key and connect it with the API. Public APIs have keys to check for authenticity of the user. Each user can have a key valid for particular time period where they could access the api.
Sending your first GET request -
Typically the get request would look like : GET http: //website_name/key = {} & query
You need to find the public APIs that are available and are useful for your application. I simply wanted to try any public API so I used one which could tell a quote randomly. Here's a list of APIs that are public sorted topic wise https://github.com/public-apis/public-apis . Go to this Git-hub repo and scroll down to see the index where you will find variety of topics on which public APIs are available with their links .
After you select your API request them for key to use it in the request. You can then read the documentation that provide on their site on how to use the API and the request format for it and different queries to get particular data. For example - there's an API to get country names , state names , the pin-codes ,etc. To use the same API in different query formats to fetch particular data is what in the documentation or how to use me guide. So states in a particular country you need to add the country to the request :
GET https: //website. com/key = {}?country = US. So country is variable as it would vary and hence is an API parameter or also called as params . You can use Postman to test APIs , build APIs ,etc . OR you can also send API requests from your java-script application. Attaching an article on it and other resources.
Resources :
1 . https://medium.com/@9cv9official/what-are-get-post-put-patch-delete-a-walkthrough-with-javascripts-fetch-api-17be31755d28 --> For using APIs in JS 2. %[https://www.postman.com/] --> Postman - the ultimate API platform 3. %[https://www.mulesoft.com/resources/api/what-is-an-api] --> Cool explanation of APIs
Thank-You . This is my first tech blog post and I'm sure there might be mistakes or more scope for improvement and I'm here for it :) Share your feedback !
Connect with me :
Subscribe to my newsletter
Read articles from Samruddhi Sangale directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by