Project

General

Profile

RESTful api in Wt

Added by Nezar Ab over 9 years ago

Hello there,

I've created a simple RESTful poll service in Wt based on apiary.io's getting started api blueprint the "poll".

I'd appreciate it if you check out the code and test it and give me your feedback on whether I should keep improving it or not.

here's the code :

https://github.com/casablancaplusplus/RestPlusPlus/tree/master


Replies (2)

RE: RESTful api in Wt - Added by Koen Deforche over 9 years ago

Hey,

I think it's well done. One change I would suggest is to use proper escaping when streaming the output.

Thus instead of:

std::string data = ...

out << "\"\" << data << "\"\";

use:

Wt::WString data = ...; // to make clear it's UTF-8

out << data.jsStringLiteral('\"');

The reason is that this properly escapes any special characters there may be inside your string which could otherwise break the JSON syntax.

Some other thoughts:

  • if your JSON service maps well onto the DBO schema, you could serialize data directly from Dbo, using Wt::Dbo::JsonSerializer
  • if your JSON service doesn't map well, you could still consider to serialize using Wt::JSon to avoid the tedious string manipulation involved in implementing the serialization, at a slight expense of lower efficiency (if you care).

Regards,

koen

RE: RESTful api in Wt - Added by Nezar Ab over 9 years ago

Thank you Mr Koen, I really appreciate the time you took to look at my code.

The things you said about proper escaping and the use of Wt::Dbo::JsonSerializer where really helpful and I would definitely consider them.

Thanks again.

    (1-2/2)