Summary:
- What Is A REST API?
- Request’s Anatomy
- The Method
- Testing Endpoints With Curl
- JSON
What is REST – Representational State Transfer API?
An API – application programming interface. It is a set of rules that allow programs to talk to each other.
REST determines how the API looks like, it’s a set of rules that developers follow when they create an API. One of these rules states that you should be able to get a piece of data when you link to a specific URL.
Each URL is called a request while the data sent back to you is called a response.
For example, you’re trying to find info about Coffee on Google. You open up Google and type “Coffee” into the search field, hit enter, and you see a list of articles about Coffee. A REST API works in a similar way, you search for something and you get a list of results back from the service you’re requesting from.
Request’s Anatomy
A request is made up of for things:
- The endpoint
- The method
The endpoint or route is the URL and has the following structure:
root-endpoint/?
The root-endpoint is the starting point of the API you’re requesting from. For example, the root-endpoint of my blog is https://cezara.iftodi.com
The path determines the resource, for example to access a specific article from https://cezara.iftodi.com where https://cezara.iftodi.com is the root and /tooluri-folosite-in-testare-automatizata-part-i-setup-javamaven/ is the path.
To know what paths are available you need to look through API’s documentation. For example to access the GitHub repos of a user you need to use this endpoint https://api.github.com/users/cezaraiftodi/repos
where cezaraiftodi is the username
The final part of an endpoint is query parameters. Technically, query parameters are not part of the REST architecture but a lot of APIs use them. Query parameters give the option to modify the request with key-value pairs. They always begin with a question mark ?
and each parameter pair is separated with an ampersand &
like this:
?query1=value1&query2=value2
If you would like to get the list of the repositories that I pushed to recently, you can set sort
to push
.Copy
https://api.github.com/users/cezaraiftodi/repos?sort=pushed
Copy
For a better understanding, I recommend watching this video: https://www.youtube.com/watch?v=s7wmiS2mSXY
Hope this article will help you better understand what is an API and a REST API.
Be the first to reply