AnCH Framework 0.1
Another C++ Hack Framework
Loading...
Searching...
No Matches
anch::rest::Router Class Reference

RESTful router. More...

#include <router.hpp>

Collaboration diagram for anch::rest::Router:

Public Member Functions

 Router ()
template<typename... P>
Routeradd (std::function< anch::rest::Response(const anch::rest::Request &, P...)> func, const std::string &path, const std::string &verb, const std::vector< std::string > &consumes, const std::vector< std::string > &produces)
template<typename... P>
Routeradd (anch::rest::EndPoint &endpoint, std::function< anch::rest::Response(const anch::rest::Request &, P...)> func)
anch::rest::Response execute (anch::rest::Request &request) noexcept

Detailed Description

RESTful router.

HTTP RESTful router which select function to execute according to its media types, HTTP verb and path.
To selected the endpoint to execute:

  1. get matching filters and throw 404 (not found) when no match
  2. filter on HTTP verb and throw 405 (method not allowed) when no match
  3. filter on content type header and throw 415 (unsupported media type) when no match
  4. filter on accept header and throw 406 (not acceptable) when no match
  5. execute first endpoint function (which are sorted in map)
Author
Vincent Lachenal
Since
0.1

Constructor & Destructor Documentation

◆ Router()

anch::rest::Router::Router ( )

Router default constructor

Here is the call graph for this function:

Member Function Documentation

◆ add() [1/2]

template<typename... P>
Router & anch::rest::Router::add ( anch::rest::EndPoint & endpoint,
std::function< anch::rest::Response(const anch::rest::Request &, P...)> func )

Register new endpoint

Parameters
endpointthe EndPoint
functhe function to execute for this endpoint
Returns
this
Exceptions
anch::rest::RouterExceptionEndpoint already exists
Here is the call graph for this function:

◆ add() [2/2]

template<typename... P>
Router & anch::rest::Router::add ( std::function< anch::rest::Response(const anch::rest::Request &, P...)> func,
const std::string & path,
const std::string & verb,
const std::vector< std::string > & consumes,
const std::vector< std::string > & produces )

Register new endpoint

Parameters
functhe function to execute for this endpoint
paththe request path
verbthe HTTP verb
consumesthe accepted input media types
producesthe accepted output media types
Returns
this
Exceptions
anch::rest::RouterExceptionEndpoint already exists
Here is the call graph for this function:

◆ execute()

anch::rest::Response anch::rest::Router::execute ( anch::rest::Request & request)
noexcept

Execute request

Parameters
requestthe HTTP request
Returns
the HTTP response

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