Project

General

Profile

Webservice: Determining response format by request's "Accept" settings

Added by Michael Schwarz about 6 years ago

Hi all,

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,

M.


Replies (2)

RE: Webservice: Determining response format by request's "Accept" settings - Added by Roel Standaert about 6 years ago

Hello Michael,

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.

Regards,

Roel

    (1-2/2)