Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST: What is difference between GET and DELETE, when we can implement same functionality in both?

In REST Web Services we have GET AND DELETE methods.

Generally we read GET is to get data from server like "getCountriesName" and DELETE is used to call resource which deletes particular object like "removeOrganization".

But if i implements DELETE to "getCountriesName" then it successfully returns country name.

So how both are different? Any real-time scenario?

like image 996
fatherazrael Avatar asked Oct 21 '25 16:10

fatherazrael


2 Answers

It is technically possible, but if you make that way, then you are not following the REST standards. I would recommend to use delete to remove resources and get to query them

like image 71
jgou Avatar answered Oct 24 '25 19:10

jgou


Looking at the Richardson Maturity Model, if you're aiming to achieve at least level 2 of REST, you'll end up with resources (Country) and HTTP VERBS:

GET /api/countries/{id}

which would also return the country's name, among other parameters. You could also issue a DELETE request towards the same URL, provided there's an endpoint that supports this - in the backend you'll usually have methods that allow a certain HTTP VERB on them. The details of the implementation depend on the language you're using, for example in C# you would have a method with mostly the same signature, but a different attribute on top of it, like [HttpDelete]).

Thinking in terms of methods (getCountriesName/removeOrganization) is not RESTful at all, but rather SOAP/RPC.

like image 26
Alexandru Marculescu Avatar answered Oct 24 '25 17:10

Alexandru Marculescu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!