REST and redirecting the response

Posted by Duane Gran on Programmers See other posts from Programmers or by Duane Gran
Published on 2012-04-30T14:13:08Z Indexed on 2012/06/01 4:48 UTC
Read the original article Hit count: 435

Filed under:
|
|

I'm developing a RESTful service. Here is a map of the current feature set:

POST /api/document/file.jpg    (creates the resource)
GET /api/document/file.jpg     (retrieves the resource)
DELETE /api/document/file.jpg  (removes the resource)

So far, it does everything you might expect. I have a particular use case where I need to set up the browser to send a POST request using the multipart/form-data encoding for the document upload but when it is completed I want to redirect them back to the form. I know how to do a redirect, but I'm not certain about how the client and server should negotiate this behavior. Two approaches I'm considering:

  1. On the server check for the multipart/form-data encoding and, if present, redirect to the referrer when the request is complete.
  2. Add a service URI of /api/document/file.jpg/redirect to redirect to the referrer when the request is complete.

I looked into setting an X header (X-myapp-redirect) but you can't tell the browser which headers to use like this. I manage the code for both the client and the server side so I'm flexible on solutions here. Is there a best practice to follow here?

© Programmers or respective owner

Related posts about rest

Related posts about http-request