tags:

views:

50

answers:

3

Hi,

I'm currently designing a RESTful API and are not sure which HTTP code is the right choice for a distinct scenario:

Clients can upload entities by using PUT to a pre-known URI. Then, the entity is processed on the server which could take some time (i.e. transcoding/processing). If this is done, the resource is available under the URI it had been uploaded to.

Now I'm unsure which is the right HTTP Response code to return, if clients query the resource before processing is done. I'm searching something like the opposite of 410 Gone. Due to the applications architecture, different clients will know the URI before processing has finished (at least the client that did the upload).

Additionally, I don't want to use WebDAV extension codes, although there would be some valid ones.

I had some initial ideas, but I don't know which fits best:

  • `307 Temporary Redirect` Redirect to placeholder resource.
  • `405 Method Not Allowed` GET is allowed only later => Clients must not cache this answer.
  • `503 Service Unavailable` Emphasizes on server-side error => Perhaps somewhat unclear for the client what actually got wrong.
  • Any other idea?

What should I pick?

Thanks in advance!

+2  A: 

You could return a 202 Accepted in response to the initial PUT and then 204 No Content to any GET requests until the representation is available.

Mike
Also thought about that one, however according to RFC2616: "This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view." Is that really what I want to express?
PartlyCloudy
It's gone from nothing to nothing, so that seems to make sense.
Mike
A: 

There are no specific HTTP codes for your use case. Maybe you want to use WebDAV's extension 423 LOCKED:

The 423 (Locked) status code means the source or destination resource of a method is locked.

AndiDog
As I already wrote in my question, I don't want to use WebDAV codes.
PartlyCloudy
A: 

Hi PartlyCloudy,

the best thing to do is this (IMHO):

return 202 and a response body that contains a status and a link to a resource where the status can be monitored.

When somone GETs the not yet ready resource, use a 307 to temp. redirect to that monitoring page.

This requires that the client understands the entity media type that contains the link to the monitoring reource so in machine 2 machine systems you'll need to mint a media type for this or at least some micro format if you use HTML.

HTH,

Jan

Jan Algermissen