This documentation is for the TIP (development tree) of NNG and may represent unreleased changes or functionality that is experimental, and is subject to change before release. The latest released version is v1.8.0. See the documentation for v1.8.0 for the most up-to-date information.

nng_http_handler_set_tree(3http)

NAME

nng_http_handler_set_tree - set HTTP handler to match trees

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.

SEE ALSO