top of page
priyak4790

Basics of REST API!

The term “REST API” is often used whenever we talk about getting data from the internet.


Lets say you search about ‘Satellites’ in google, then you get a list of data related to satellites. The REST API works in similar way, you search for something and you get list of results you are requesting back from the service you are requesting from.


An API is Application Programming Interface, which allows two programs to exchange the data. REST(Representational State Transfer) designs these APIs and decides how these APIs looks like. It is a set of rules that developers decide while they create APIs in the server and allow them to interact with the clients.


Image: stabene.net


The Request can be broken into different parts:

  1. The endpoint URL: An application implementing a RESTful API will define one or more URL endpoints with

- The root URL: It is the starting point of an API you are requesting from.

Eg: The endpoint of amazon is https://www.amazon.com

  • The path: path determines the resource you are requesting for. It is just like clicking links in a website.

Eg: clicking on contents in wikipedia page

https://en.wikipedia.org/wiki/Wikipedia:Contents - here /wiki/Wikipedia:Contents is the path.

- Query parameters: The final part is the query parameter, it gives you to modify the request in key value pairs. They begin question mark(?) and each parameter is separated with ‘&’

Like this : ?query1=value1&query2=value2

Here - ‘?title=Hockey&oldid=1017782528’ is the query parameter.

2. The method: It is the request we send to the server namely:

  • GET

  • POST

  • PUT

  • PATCH

  • DELETE

These perform the four possible operations Create, Read, Update and Delete. You can see more details about these in my previous blog https://www.numpyninja.com/post/connecting-through-apis

3.The headers: Headers are used to give information to both client and server. It can be used for purposes like authentication and providing details about the body. The header is separated by colon.

Eg: Content-Type:text/xml

The above example shows the file is in xml format.

4. The Body: This is the actual data you have requested.

Eg: Suppose we send a GET request with following path:

/employees?lastName=Smith&age=30

Then we get response as :

[

{

"firstName": "John",

"lastName": "Smith",

"age": 30

}

]

90 views

Recent Posts

See All
bottom of page