I am designing an RESTful API for our product and have encountered the need for asynchronous actions. The recommendation from several books is to use the 202 response code and provide a link to the “status” of the action in the Location: header.
While trying to implement this in a Grails environment, developers recommended using Grails ability to create links automatically (docs here). The problem is that then an administrator has to define the grails.serverURL in a configuration (which is just one more thing to go wrong).
I proposed that we use the request to reflect back the appropriate URL by simply replacing the requested resource “/rest/foo” with the newly created “status” resource “/rest/bar/status-42”. Is it appropriate to use HttpServletRequest.getRequestURL() in this way? If so, can you comment on the reliability of getRequestURL() (I’ve heard disturbing reports)? If not, why not, and any other suggestions?
It is not bad form. I have no evidence to back this up but the absence of people of people screaming, “NO! NO! Anything but THAT!” and the javadocs I linked to. I’ll reply back here and change my answer if it turned out to be a bad idea 🙂