Webservice: Determining response format by request's "Accept" settings
Added by Michael Schwarz about 5 years ago
I'm developing a REST webservice with Wt and I would like to support both JSON and XML responses.
In the resource's handleRequest() method, I could get the "Accept" header info through request.headerValue("Accept"), then parse the returned string for desired formats and their priorities.
My question is if this is the most elegant way to go or if Wt provides an easier way to get this information. Not that mine would require a terrible amount of work, I just don't want to reinvent a possibly existing here. :)
On a side note:
The documentation on Wt::Http::Request::headerValue() says:
@Returns a header value.
Returns a header value, or an empty string if the header was present.@
First line is redundant and in the second, I'm pretty sure it should read "if the header was NOT present". :)
Thanks and regards,
RE: Webservice: Determining response format by request's "Accept" settings - Added by Roel Standaert about 5 years ago
Wt currently offers no better way to do this than the method you are proposing. Your way of doing it would be correct.
You're right about the documentation, I will fix that.
RE: Webservice: Determining response format by request's "Accept" settings - Added by Michael Schwarz about 5 years ago
Thanks for the quick response, Roel!