Mantis App v0.1.13
Loading...
Searching...
No Matches
mantis::HttpUnit Class Reference

#include <http.h>

Public Member Functions

 HttpUnit ()
 
void Get (const std::string &path, RouteHandlerFunc handler, std::initializer_list< Middleware > middlewares={})
 
void Post (const std::string &path, RouteHandlerFunc handler, std::initializer_list< Middleware > middlewares={})
 
void Patch (const std::string &path, RouteHandlerFunc handler, std::initializer_list< Middleware > middlewares={})
 
void Delete (const std::string &path, RouteHandlerFunc handler, std::initializer_list< Middleware > middlewares={})
 
bool listen (const std::string &host, const int &port)
 Bind to a port and start listening for requests.
 
void close ()
 Close the HTTP server connection.
 
RouteRegistryrouteRegistry ()
 Fetch the underlying route registry, check.
 
httplib::Server & server ()
 

Static Public Member Functions

static Contextcontext ()
 

Public Attributes

const std::string _class_ = "mantis::HttpUnit"
 

Detailed Description

Class wrapper around httplib methods allowing for injection of the middleware and context functionality. By default, httplib supports pre/post global middlewares, we're therefore adding a layer to scope middlewares to specific routes.

Also, to allow sharing data between middlewares and handler func, we are adding Context in the handler functions.

Constructor & Destructor Documentation

◆ HttpUnit()

mantis::HttpUnit::HttpUnit ( )

Member Function Documentation

◆ close()

void mantis::HttpUnit::close ( )

Close the HTTP server connection.

◆ context()

mantis::Context & mantis::HttpUnit::context ( )
static

◆ Delete()

void mantis::HttpUnit::Delete ( const std::string &  path,
RouteHandlerFunc  handler,
std::initializer_list< Middleware middlewares = {} 
)

◆ Get()

void mantis::HttpUnit::Get ( const std::string &  path,
RouteHandlerFunc  handler,
std::initializer_list< Middleware middlewares = {} 
)

◆ listen()

bool mantis::HttpUnit::listen ( const std::string &  host,
const int &  port 
)

Bind to a port and start listening for requests.

Parameters
hostHTTP server host.
portHTTP server port.
Returns
Flag if successful or not.

◆ Patch()

void mantis::HttpUnit::Patch ( const std::string &  path,
RouteHandlerFunc  handler,
std::initializer_list< Middleware middlewares = {} 
)

◆ Post()

void mantis::HttpUnit::Post ( const std::string &  path,
RouteHandlerFunc  handler,
std::initializer_list< Middleware middlewares = {} 
)

◆ routeRegistry()

mantis::RouteRegistry & mantis::HttpUnit::routeRegistry ( )

Fetch the underlying route registry, check.

See also
RouteRegistry.
Returns
Ref to the underlying route registry object.

◆ server()

httplib::Server & mantis::HttpUnit::server ( )

Member Data Documentation

◆ _class_

const std::string mantis::HttpUnit::_class_ = "mantis::HttpUnit"

The documentation for this class was generated from the following files: