Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Restful API up and running using Wt

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.

like image 685
Trevor Donahue Avatar asked Sep 16 '14 03:09

Trevor Donahue


Video Answer


1 Answers

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);
like image 85
hank Avatar answered Oct 20 '22 23:10

hank