feat: add initial routing function

This commit is contained in:
Jef Roosens 2024-02-22 17:57:58 +01:00
parent 0e1d5d3f23
commit 386d83ec93
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
4 changed files with 103 additions and 24 deletions

View file

@ -13,6 +13,7 @@ typedef enum lnm_http_method {
lnm_http_method_patch,
lnm_http_method_delete,
lnm_http_method_head,
lnm_http_method_total,
} lnm_http_method;
extern const char *lnm_http_status_names[][32];

39
include/lnm/http/router.h Normal file
View file

@ -0,0 +1,39 @@
#ifndef LNM_HTTP_ROUTER
#define LNM_HTTP_ROUTER
#include "lnm/common.h"
#include "lnm/http/consts.h"
typedef struct lnm_http_route lnm_http_route;
typedef struct lnm_http_router lnm_http_router;
typedef enum lnm_http_route_err {
lnm_http_route_err_match = 0,
lnm_http_route_err_unknown_route = 1,
lnm_http_route_err_unknown_method = 2,
} lnm_http_route_err;
/**
* Allocate and initialize a new http_router.
*/
lnm_err lnm_http_router_init(lnm_http_router **out);
void lnm_http_router_free(lnm_http_router *router);
lnm_err lnm_http_router_add(lnm_http_route **out, lnm_http_router *http_router,
lnm_http_method method, const char *path);
/**
* Add all of the child router's routes to the parent router, under the given
* route prefix.
*/
lnm_err lnm_http_router_nest(lnm_http_router *parent,
const lnm_http_router *child, const char *prefix);
lnm_http_route_err lnm_http_router_route(const lnm_http_route **out,
const lnm_http_router *router,
lnm_http_method method,
const char *path);
#endif