loentar / ngrest

Fast and easy C++ RESTful WebServices framework
Apache License 2.0
465 stars 94 forks source link

Is there a way to return result as json without the "result" element? #62

Closed AvnerGidron305 closed 6 years ago

AvnerGidron305 commented 6 years ago

Hi, first of all great project!! second, I was wondering if there is a way to return the result as pure json? return result is now: {"result":{"Pets":[{"species":"canine","name":"spot","birthday":"Jan 1, 2010"},{"species":"feline","name":"puff","birthday":"July 4, 2014"}]}} I would like to get: {"pets":[{"species":"canine","name":"spot","birthday":"Jan 1, 2010"},{"species":"feline","name":"puff","birthday":"July 4, 2014"}]}

AvnerGidron305 commented 6 years ago

found this: Please upgrade ngrest and try new attributes: inlineResult - to make particular operation respond without being wrapped into "result" interface.defaultInlineResult - make the same as above but for any services and operations declared within this interface file You can apply either or both, inlineResult takes precedence over interface.defaultInlineResult. By default both attributes has false value.

-- yourservice.h

// *interface.defaultInlineResult: true

class YourService: public ngrest::Service { ... // *inlineResult: true std::list getPets(); // result will be inlined due to inlineResult: true

// *inlineResult: false
std::list<Pet> getPetsNoInline(); // result will be NOT inlined due to inlineResult: false

std::list<Pet> getPets2();  // result will be inlined due to interface.defaultInlineResult