Re: Modeling conditional update based on existence of a dependent resource
Mike Kelly <[email protected]>
| Newsgroups | gmane.comp.web.services.rest |
|---|---|
| Message-ID | <CANqiZJb40DJWNXT_cfFYDGn9jBULdXm+mm4-moPLdb7oMpGOJA@mail.gmail.com> |
On Tue, Jul 3, 2012 at 12:33 PM, Shaunak Kashyap <[email protected]>wrote: > ** > > > Hi folks, > > I am looking to model an interaction in my REST application where the > client should only be allowed to modify a resource (say "B") if another > resource (say "A") exists. > > Using HTTP, if resource A exists, I would like PUT /uri/for/resource/B to > succeed. If resource B does not exist, I would like the same PUT request to > fail, responding with a status code that indicates to the client that > resource A does not exist. So what is a good status code to respond with in > the failure case? I considered 403 Forbidden but its semantics say that > "the request should not be repeated". This does not quite make sense in my > application since resource A might come into existence in the future, > making it okay for the client to re-issue the same PUT request for resource > B. > Would 404 not suffice here? > > Alternatively (or additionally?), perhaps the client could issue a > conditional PUT on resource B which would only succeed if resource A > existed. How could I express such a condition in HTTP? I considered using > the If-Match request header but that seems to apply to representations of > the same resource (in my example, B) rather than of other resources (in my > example, A). > You could use a Link header in the error response that has a relation type called something like "depends-on-existence", and point that link to resource A. Cheers, M