为什么要使用HTTP动词? [英] Why use HTTP verbs?

查看:124
本文介绍了为什么要使用HTTP动词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为动词的目标是诸如server.domain/getallrecords或server.domain/delete1record之类的URL或类似名称.而且getallrecords,delete1record是专门为特定目的而设计的,为什么我们在这里需要动词?

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 ?

致电

server.domain/getallrecords or 
server.domain/delete1record 

或调用(或发布或删除)上述任何URL吗?

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

推荐答案

如果您采用 RPC方式,则HTTP动词似乎毫无用处.

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

HTTP动词是REST样式HTTP服务的良好伴侣,因为面向资源的URI不会包含动作标识符,而是资源.

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

例如,server.domain/getallrecords将为server.domain/records,如果您使用HTTP/GET对此资源执行请求,则资源将被映射到服务器方法,如果您使用HTTP执行相同的请求,则该服务器方法将返回所有记录. /POST,它将创建一条新记录,依此类推.

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.

您需要确定: RPC

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.

这篇关于为什么要使用HTTP动词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆