Typedefs | Functions
http_router.h File Reference

HTTP router. More...

Typedefs

typedef struct vtm_http_router vtm_http_router
 

Functions

VTM_API vtm_http_router * vtm_http_router_new (void)
 
VTM_API void vtm_http_router_free (vtm_http_router *rtr)
 
VTM_API int vtm_http_router_add_rt (vtm_http_router *rtr, const char *path, struct vtm_http_route *rt)
 
VTM_API int vtm_http_router_static_rt (vtm_http_router *rtr, const char *path, vtm_http_static_rt_handle_fn fn)
 
VTM_API int vtm_http_router_handle (vtm_http_router *rtr, struct vtm_http_ctx *ctx, struct vtm_http_req *req, vtm_http_res *res)
 

Function Documentation

VTM_API vtm_http_router* vtm_http_router_new ( void  )

Creates a new router.

Returns
the created router
NULL if an error occured
VTM_API void vtm_http_router_free ( vtm_http_router *  rtr)

Releases the router and all allocated resources.

This call also releases all routes that were added to the router. After this call the router pointer is no longer valid.

Parameters
rtrthe router that should be released
VTM_API int vtm_http_router_add_rt ( vtm_http_router *  rtr,
const char *  path,
struct vtm_http_route rt 
)

Binds the route to the given URL path.

Parameters
rtrthe router where the route should be added
paththe URL path where the route should be bound to
rtthe route that should be added
Returns
VTM_OK if the route was added successfully
VTM_ERROR if an error occured
VTM_API int vtm_http_router_static_rt ( vtm_http_router *  rtr,
const char *  path,
vtm_http_static_rt_handle_fn  fn 
)

Adds a static route for the given path.

Parameters
rtrthe router where the route should be added
paththe URL path where the route should be bound to
fnthe callback function that should handle the route
Returns
VTM_OK if the route was added successfully
VTM_ERROR if an error occured
VTM_API int vtm_http_router_handle ( vtm_http_router *  rtr,
struct vtm_http_ctx ctx,
struct vtm_http_req req,
vtm_http_res *  res 
)

Lets the router handle a given request.

Parameters
rtrthe router that should handle a request
ctxthe context of the request
reqthe request that should be handled
resthe response that musst be prepared
Returns
VTM_OK if the request was handled by the router
VTM_E_NOT_HANDLED if the request was not handled by any route
VTM_E_IO_UNKNOWN or VTM_ERROR if an error occured while handling the request