Skip to content

How to extended it

Henrique Rocha edited this page Aug 25, 2021 · 1 revision

Before even begin, it’s recommended to know how to use Mongoose!

For implementing more routes:

Add another field to the enum e_uri on enki.h file:

enum e_uri
{
	HOME_ROUTE,
	DOCS_ROUTE,
	DOCS_ROUTE_,
	API_BASE_ROUTE,
	API_BASE_ROUTE_,
	API_MAIN_ROUTE,
	API_EXAMPLE
};

Add another else if statement in the function get_uri on router.c as follows:

else if (mg_http_match_uri(request, "/example"))
	return (API_EXAMPLE);

Then edit the function handle_routes on router.c as follows:

Add an else if with your route, method and reply.

else if (uri == API_EXAMPLE && method == GET)
	mg_http_reply(c, 200, "", "EXAMPLE");

It’s done!

Clone this wiki locally