API Methods

There are several different ways an API can be called from our frontend website or app. They are called Methods.

We have different ways to connect with a api which do different things.

Usually There's GET, POST, PUT & DELETE methods to call a API & these are the different ways to either send data to a server or get data from it.

GET

So this is the most common one and used to get data from a server. Say you have an API and you want to get data from it, you call the API with GET.

For Example this api returns a list of JSON objects https://jsonplaceholder.typicode.com/todos/. Get requests can be opened directly from a browser.

This is a read only method, which means if you have an api you want to be publicly available, this is the best way to do so.

This is the R in CRUD.

POST

The POST method is usually used send a request to create a new entry in a your database.

Though you can send some amount of data to a GET method by appending it to the URL. POST let's you transfer huge amounts of data and also allows you to transfer the data in different formats if we wanted to.

This is the C in CRUD.

Usually we send the data in a body parameter to a POST method, this way your data won't be exposed inline GET methods query parameters.

PUT

This works similar to a POST request, but is contextual, PUT method is usually used when you want to update a existing item in your server.

This is the U in CRUD.

DELETE

As the name says, this is used for deleting someting in your Database.

NOTE: It is not necessary that you always have to use PUT to update and DELETE to delete something from your sever, you can even do so with a POST method, use PUT and DELETE is more readable and hence always better to use them.

Finally the D in CRUD.

Apart from these there is also PATCH method available, which is similar to PUT method but hardly used.

Next Chapter

Setup API Environment