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 ?
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.
In a rest API, say you have 4 endpoints for an inventory API
is for creation of an item
is for modification (edit operation) of an item(s)
is for deletion of an item
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With