Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use HTTP verbs?

Tags:

.net

http

asp.net

Since verbs target a URL like server.domain/getallrecords or server.domain/delete1record or something similar. And getallrecords, delete1record are specifically designed for specific purposes, why do we need Verbs here ?

Whats the difference between a get call to

server.domain/getallrecords or 
server.domain/delete1record 

or a put (or post or delete) call to any of the above URL ?

like image 548
user4032346 Avatar asked Feb 12 '23 01:02

user4032346


2 Answers

If you go the RPC way it seems like HTTP verbs are useless.

HTTP verbs are a good companion of REST-style HTTP services, because resource-oriented URIs won't contain an action identifier but a resource.

For example, server.domain/getallrecords would be server.domain/records and if you perform a request to this resource using HTTP/GET, resource will be mapped to a server method which will return all records, if you perform the same request using HTTP/POST, it would create a new record, and so on.

You need to decide: RPC or REST, and depending on this, you'll find HTTP verbs useful or not. I would suggest you that using HTTP verbs is a good way of using a well-known protocol - HTTP - with predefined verbs, instead of inventing your own ones. But again, it depends on your own thoughts, preferences and requirements.

like image 127
Matías Fidemraizer Avatar answered Feb 26 '23 17:02

Matías Fidemraizer


In a rest API, say you have 4 endpoints for an inventory API

  1. is for creation of an item

  2. is for modification (edit operation) of an item(s)

  3. is for deletion of an item

  4. is for view of an item The API endpoint would look like these:

    servername.domain/createItem

    servername.domain/editItem

    servername.domain/deleteItem

    servername.domain/viewItems

but if we use verbs, we will only need 1 endpoint, since the endpoint can figure out what operation to do given the HTTP verb

servername.domain/inventory

if that endpoint receives a GET, its the /viewItems if that endpoint receives a POST, its the /createItems if that endpoint receives a PUT, its the /editItems if that endpoint receives a DELETE, its the /deleteItems

like image 25
Frederick G. Sandalo Avatar answered Feb 26 '23 16:02

Frederick G. Sandalo