在 PUT 请求的 URI 中包含 Id [英] Including Id in URI for PUT requests

查看:91
本文介绍了在 PUT 请求的 URI 中包含 Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一些关于使用 REST 服务适当使用 URI 的文档,我遇到了一个基本 GET .. DELETE 请求的示例.

I was reading some documents about the appropriate use of URI's using rest services and I came across an example for basic GET .. DELETE requests.

示例 uri 是:

获取所有用户

GET http://mydomain.org/api/users

获取特定用户

GET http://mydomain.org/api/users/1

更新用户

PUT http://mydomain.org/api/users/1

删除用户

DELETE http://mydomain.org/api/users/1

用户资源可以是以下形式的 JSON 或 XML:

A user resource would be either JSON or XML in the form of:

{
    Id: 1,
    FirstName: 'John',
    LastName: 'Doe'
}

我的问题是这个.为了维护 REST 原则,是否需要在 PUT 请求的 URI 中包含资源的 id?

My question is this. To maintain REST principles, is it required to include the id of the resource within the URI for PUT requests?

推荐答案

PUT 方法请求创建目标资源的状态或替换为由包含在请求消息负载中的表示定义的状态.

The PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload.

您希望将资源PUT 到您打算从中GET 的同一 URI.

You want to PUT a resource to the same URI you intend to GET it from.

RFC 72314.3.4 PUT

这篇关于在 PUT 请求的 URI 中包含 Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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