restful architecture - PUT on REST collection. Do I provide addresses? -
when put on rest collection should provide addresses of members in collection?
put on dogs address specified
[{"name":"sparky", "id":1}, {"name":"rusty", "id":2}]
or...
put on dogs without address specified
[{"name":"sparky"}, {"name":"rusty"}]
and let server return locations of new members in collection. in case row ids in table.
if sending put
replace every resource in entire collection, should send full new / updated entities.
- if
id
part of entity, should send within entity, client has nothing uri (a.k.a "address") of element, clients have knowledge how uri build server. - if
id
not part of entity client, should not send within entity.
but both cases possible , server accept both, important the put
on collection behaves in http/1.1 specs described:
the put method requests enclosed entity stored under supplied request-uri.
so if put
on /api/animals/dogs/
dogs found under /dogs/
, not e.g. /cats/
if request-uri refers existing resource, enclosed entity should considered modified version of 1 residing on origin server
that means put
on collection, delectes whole collection , creates new 1 entities given in body of method call.
if request-uri not point existing resource [...] origin server can create resource uri.
that means if /animals/dogs/
empty should create new collection there.