Am 20.11.2013 14:59, schrieb Dicebot:

On Wed, 20 Nov 2013 09:13:14 GMT, Sönke Ludwig wrote:

1) The main reason is that I would like to provide different media (ContentType) to people. So far, XML, JSON, HTML.
2) I'll also use ContentType over the URL-way for versioning (I'm aware of it's drawbacks).
3) And of course, I'd like to take full advantages of it by using objects / structs in the client, not return a string that I have to pass to another function.

So it looks like two additions to the REST system would be necessary: Allow to specify the serializer (JSON/XML/...) that is used, and allow to specify a custom suffix for each URL (".json"/".xml"/...). Then I'd imagine this to work in that scenario:

router.registerRestInterface!JsonStringSerializer(..., ".json");
router.registerRestInterface!XMLStringSerializer(..., ".xml");
router.registerRestInterface!HTMLStringSerializer(..., ".html");

Of course, the XML and HTML serializers would also have to be written, but that's trivial.

An alternative option may be to expose some struct/class that controls serialization and writing data to response via @after so that it can be tweaked in any way on per-method basis. I have never thought much about this development direction when working on REST part so hard to make any good proposals at once but sounds like a reasonable feature set to support.

But that would mean that each method has to be implemented for each
content type (unless I'm missing something).

I'm planning to rework the REST interface code a bit so that the MethodStyle is passed as a template parameter instead of as a runtime parameter (this would allow to shift a great amount of work from runtime to compile time and thus improve performance). I guess in that process it will be easy to also make the serializer a template argument. But I can't give an exact time schedule for this, yet.

Damn, I have kept being tempted to move it to template parameter since first changes to this module and resisted all the time because it seemed like intended choice :D

Yeah, let's say it was some kind of historic accident that I've never
really noticed because I've always left the parameter to its default ;)