Modeling conditional update based on existence of a dependent resource

Shaunak Kashyap <[email protected]>
Newsgroups gmane.comp.web.services.rest
Message-ID <CAMiVsfLaFshcs1BGeEP7iWwfH9GCp1Fbwytiid_1hprMUfnF0A@mail.gmail.com>
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.

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).

Thank you,

Shaunak

-- 
"Now the hardness of this world slowly grinds your dreams away / Makin' a
fool's joke out of the promises we make" --- Bruce Springsteen, "Blood
Brothers"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.