On Thu, 16 Oct 2014 13:49:57 GMT, Sönke Ludwig wrote:

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?

Thank you for your answer!

I'm pretty new to D so I don't think my opinion worth a lot, but a low level attribute or an out parameter would be a great solution. As I understand there's no way to manage this easily which probably means that nothing would interact with it in a bad way. It depends on what features you have in mind about the status code for the future but these two solutions seems to be clearer and make source code easy to understand.