Including Id in URI for PUT requests

前端 未结 4 1546
庸人自扰
庸人自扰 2020-12-24 12:14

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.

The example uri\'

4条回答
  •  旧巷少年郎
    2020-12-24 12:46

    PUT http://example.com/api/users + body behaves like the put of a map with the key http://example.com/api/users and the value the body. A new entry is created if none exists, else the existing one is overridden.

    Question: what is the resource behind http://example.com/api/users ?

    Answer: the same than the one provided by GET http://example.com/api/users, the list of all users.

    So, the command PUT http://example.com/api/users means that you replace the list of all users with the one you provide.

    For consistency, the body should contain an array of users:

    [
      {
        Id: 1,
        FirstName: 'John',
        LastName: 'Doe'
      },
      {
        Id: 2,
        FirstName: 'Albert',
        LastName: 'Einstein'
      }
    ]
    

提交回复
热议问题