Why use HTTP verbs?

2019-09-10 02:55发布

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 ?

1条回答
Viruses.
2楼-- · 2019-09-10 03:30

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.

查看更多
登录 后发表回答