How to get Restful API up and running using Wt

情到浓时终转凉″ 提交于 2020-01-22 20:03:45

问题


I have a running Wt application based on the tutorials all over the web and I was wondering if there is an elegant way of using Wt to add a some Restful API functionality.

I have a few resources I can expose from my current application and I don't want to implement any patches.

If someone has a good idea of how to do that, or even a suggestion of some JSON library that can make the development a breeze, I'd be very thankful.


回答1:


You should subclass WResource and implement the WResource::handleRequest method to provide REST API functionality. Then you should add your resource to your server using WServer::addResource

Also you should ensure that you add your resource to the server before the main Wt appliaction entry point:

Wt::WServer server(argv[0]);
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
server.addResource(new MyResource, "/api"));
server.addEntryPoint(Wt::Application, createApplication);


来源:https://stackoverflow.com/questions/25860068/how-to-get-restful-api-up-and-running-using-wt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!