I send json to url localhost/json. how can I process this request? how is it perfoming at all? Is it necessery implement my own WResource, WServer, WApplication and something else? Please explain me, how works with it using Wt.
/* in LoginForm() */
...
client.done().connect(this, &LoginForm::receiveJSONresponse);
...
void LoginForm::sendLogInRequest()
{
Json::Object data;
data["action"] = "login";
data["username"] = usernameTextEdit.text();
data["password"] = passwordTextEdit.text();
Http::Message msg;
msg.addHeader("Content-Type", "application/json");
msg.addHeader("Accept", "application/json");
msg.addBodyText(Json::serialize(data));
client.request(Http::Post, "http://localhost/json", msg);
}
You'll need to specialize a WResource, and in handleRequest() look at the data that was posted.
WResource has two ways to be used: either session-specific or global. A session-specific resource has a random URL, while a global resource has a specified (constant) URL.
For what you ask, to attach the resource to localhost/json, the resource has to be attached to a fixed URL, so indeed you do this through the WServer API. Take a look at the blog example to see how the BlogRSSFeed is deployed as static resource. You can use this as a start point and modify handleRequest to process the json posted to the resource.