Function handler in general and json function in particular are the
easiest way to add logic to to handler.
While in some cases the method can return immediately, there are cases
when it is required to perform an async operation, to support those
cases, the function handler was modified to use future.
If it receives an old style function, it would wrap the results in a
make_ready_future. This you could still assign a function like:
new function_handler([](const_req req) {
return "hello";
});
It would no also support a function that return a future json so it is
no possible to assign logic like:
new function_handler([](std::unique_ptr<request> req) {
return make_ready_future<json::json_return_type>("json-future");
});
For the future case note that auto-boxing still works, although you now
need to use make_ready_future.
The json_path was also modified to accept the new kind of function, to
support the common case of route definition based on the code
generation.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Json path are used when parsing the swagger files. Each path represent
an operation in the swagger files.
They are used to simplified setting a handler or a function to a path.
For example: the code generation would define a json_path like:
path_description hello_world("/hello/world",GET,"hello_world", {},{});
Now to define the handler that would use hello_world, you can simply do:
hello_world.set(r,
[](const_req req) {
return "hello world";
});
When r is a reference to a route object.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>