request.h

The request.h module provides functions for interacting with mn_request objects. Learn more at Requests.

API

enum mn_method

An HTTP method.

unsigned int MN_METHOD_GET = 0
struct mn_query_param

A single query param. Given e.g. abc=def, the key corresponds to abc whereas value corresponds to def.

struct mn_view key
struct mn_view value
struct mn_request

A client request.

enum mn_method method

The HTTP method sent by the client.

struct mn_str uri

The path and query portion of the URI used by the client.

struct mn_view path

The path portion of the URI used by the client.

struct mn_query_param query[MN_REQUEST_MAX_QUERY_PARAMS]

The query parameters sent by the client. There are a total of query_count valid key/value parameters set.

size_t query_count

The number of query parameters sent by the client.

struct mn_view captures[MN_REQUEST_MAX_CAPTURES]

The captures pulled from the path.

size_t capture_count

The number of string fragments captured.

typedef struct mn_status mn_route_handler_t(
struct mn_request const,
struct mn_response *const
)

A type alias for a user-defined handler function.

struct mn_route

A route. These are pattern-matched against client requests. For more information, refer to Routing. The following is a typical example of how a router might be defined:

static struct mn_route route_root;
static struct mn_route route_abc;
static struct mn_route route_def;

static struct mn_route route_root = {
    .method = MN_METHOD_GET,
    .pattern = mn_str_lit("/"),
    .handler = handle_root,
    .next = &route_abc,
  };

static struct mn_route route_abc = {
    .method = MN_METHOD_GET,
    .pattern = mn_str_lit("/abc"),
    .handler = handle_abc,
    .next = &route_def,
  };

static struct mn_route route_def = {
    .method = MN_METHOD_GET,
    .pattern = mn_str_lit("/def"),
    .handler = handle_def,
  };
enum mn_method method

The method used to match against the request.

struct mn_str pattern

The pattern used to match against the request.

mn_route_handler_t *handler

The user-defined handler function to be called on a successful match.

struct mn_route *next

The next route to try matching against if this route failed to do so.