On Wed, 15 Oct 2014 15:47:42 GMT, Julien Ganichot wrote:

Hi,

I am currently using the REST api with vibe.d

I want to chage the status code of specific routes depending on what happens but I can't seem to find a way to do this directly with the REST interface, is there a keyword corresponding to it like @path?

Thanks

There are currently two ways to achieve this:

  • throw a HTTPStatusException with the appropriate status code
  • use @after to get direct access to the response object

The second option should work similar to this:

interface MyService {
	static void setReturnCode(HTTPServerRequest req, HTTPServerResponse res)
	{
		res.statusCode = 201;
	}

	@after!setReturnCode
	void getSomeResource();
}

Both solutions may not be very nice in certain situations, so I think there should be another way to achieve the same result, but simpler. Maybe by encoding it in the return value, using an out parameter, or by adding higher level attributes (@createsResource, @processesAsynchronously, @resourceType!(RT.create)) or a low level attribute (@httpStatusCode). Do you (or anyone else) have an opinion on this?