Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
Router.h File Reference

HTTP routing with middleware and optional JWT-based authorization. Part of the PicoFramework HTTP server. This module provides the Router class, which manages HTTP routes, middleware, and optional JWT authentication. It allows dynamic route registration, regex-based path matching, and supports global and per-route middleware. The Router can handle requests, invoke appropriate handlers, and apply middleware functions in sequence. It also includes a built-in route handler for testing JWT tokens at the /auth endpoint. More...

#include <vector>
#include <string>
#include <unordered_map>
#include <functional>
#include <FreeRTOS.h>
#include <semphr.h>
#include "http/RouteTypes.h"
#include "http/HttpRequest.h"
#include "http/HttpResponse.h"
#include "http/HttpFileserver.h"
+ Include dependency graph for Router.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Router
 The central router for handling HTTP requests and middleware. More...
 

Typedefs

using RouteHandler = std::function< void(HttpRequest &, HttpResponse &, const RouteMatch &)>
 Function signature for HTTP route handlers.
 
using Middleware = std::function< bool(HttpRequest &, HttpResponse &, const RouteMatch &)>
 Function signature for middleware.
 

Detailed Description

Author
Ian Archbell
Version
0.1
Date
2025-03-26
License:\n MIT License

Definition in file Router.h.

Typedef Documentation

◆ Middleware

using Middleware = std::function<bool(HttpRequest &, HttpResponse &, const RouteMatch &)>

Middleware may short-circuit request handling by returning false.

Definition at line 48 of file Router.h.

◆ RouteHandler

using RouteHandler = std::function<void(HttpRequest &, HttpResponse &, const RouteMatch &)>

Route handlers receive the parsed request, response object, and any captured parameters from dynamic paths (e.g., /device/{id}).

Definition at line 41 of file Router.h.