SYNOPSIS
#include <nng/nng.h>
#include <nng/supplemental/http/http.h>
int nng_http_handler_set_tree(nng_http_handler *handler);
int nng_http_handler_set_tree_exclusive(nng_http_handler *handler);
DESCRIPTION
The nng_http_handler_set_tree()
function causes the handler to be matched if the request URI sent
by the client is a logical child of the path for handler, and no more specific
handler has been registered.
The nng_http_handler_set_tree_exclusive()
function is similar to nng_http_server_set_tree()
with the distinction that the handler will be considered to exclusively handle its request URI.
Unlike nng_http_server_set_tree()
, it will not be possible to register additional
handlers in logical subdirectories of handler.
This is useful in cases when the handler would like to examine the entire path and possibly behave differently; for example a REST API that uses the rest of the path to pass additional parameters.
These methods are useful when constructing API handlers where a single service address (path) supports dynamically generated children. |
The non-exclusive form is also useful for providing a default handler to be generated when a more specific child does not exist. This can provide a better experience for users than the standard 404 error handling. |
RETURN VALUES
This function returns 0 on success, and non-zero otherwise.
ERRORS
NNG_ENOMEM
|
Insufficient free memory exists. |
NNG_ENOTSUP
|
No support for HTTP in the library. |