REST and redirecting the response
- by Duane Gran
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:
On the server check for the multipart/form-data encoding and, if present, redirect to the referrer when the request is complete.
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?