AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::rest::Endpoint< F > Class Template Reference

#include <endpoint.hpp>

Inheritance diagram for anch::rest::Endpoint< F >:
Collaboration diagram for anch::rest::Endpoint< F >:

Public Member Functions

 Endpoint (anch::rest::Method method, std::string pattern, std::vector< std::string > parameterNames, F function)
template<typename C>
Endpoint & produces ()
template<typename C>
Endpoint & consumes ()
Endpoint & status (anch::rest::Status status)
virtual anch::rest::Response handle (anch::rest::Request &request, std::vector< std::string > &parameters) override
virtual std::size_t getPathParameterCount () const noexcept override
virtual std::optional< std::string > check () const override
Public Member Functions inherited from anch::rest::Route
 Route (anch::rest::Method method, std::string pattern, std::vector< std::string > parameterNames)
 Route (const Route &)=delete
virtual ~Route ()
Route & operator= (const Route &)=delete
anch::rest::Method getMethod () const noexcept
const std::string & getPattern () const noexcept
const std::vector< std::string > & getParameterNames () const noexcept

Additional Inherited Members

Protected Attributes inherited from anch::rest::Route
anch::rest::Method _method
std::string _pattern
std::vector< std::string > _parameterNames

Detailed Description

template<typename F>
class anch::rest::Endpoint< F >

Endpoint function bound to a route.
Function arguments are, in order:

  • const anch::rest::Request& (optional)
  • path parameters, in pattern order (types supported by ParamConverter , 400 when invalid)
  • Body (optional): deserialized with the codec matching Content-Type (415 when not consumed, 400 when missing or invalid)
  • or std::istream& (optional): raw body stream, whatever the Content-Type is (absent included, no codec: read it with const Request& ), empty without body

Function result:

  • Response : sent as is
  • void : 204
  • std::optional<T> : 404 when empty, T otherwise
  • T : serialized with the codec negotiated with Accept (406 when not acceptable)
Template Parameters
Fthe function type
Author
Vincent Lachenal
Since
0.2

Constructor & Destructor Documentation

◆ Endpoint()

template<typename F>
anch::rest::Endpoint< F >::Endpoint ( anch::rest::Method method,
std::string pattern,
std::vector< std::string > parameterNames,
F function )

Endpoint constructor

Parameters
methodthe method
patternthe path pattern
parameterNamesthe path parameter names
functionthe endpoint function

Member Function Documentation

◆ check()

template<typename F>
virtual std::optional< std::string > anch::rest::Endpoint< F >::check ( ) const
overridevirtual

Check endpoint configuration: a serialized result needs a produced media type, a body needs a consumed media type

Returns
the error message, empty when endpoint is valid

Implements anch::rest::Route.

Here is the call graph for this function:

◆ consumes()

template<typename F>
template<typename C>
Endpoint & anch::rest::Endpoint< F >::consumes ( )

Add a consumed media type: body is deserialized with codec C when request Content-Type is the codec media type (parameters such as charset are ignored)

Template Parameters
Cthe codec (see anch::codec::Deserializer )
Returns
this
Here is the call graph for this function:

◆ getPathParameterCount()

template<typename F>
virtual std::size_t anch::rest::Endpoint< F >::getPathParameterCount ( ) const
overridevirtualnoexcept

Get the number of path parameters expected by endpoint

Returns
the number of path parameters

Implements anch::rest::Route.

◆ handle()

template<typename F>
virtual anch::rest::Response anch::rest::Endpoint< F >::handle ( anch::rest::Request & request,
std::vector< std::string > & parameters )
overridevirtual

Execute endpoint

Parameters
requestthe request
parametersthe decoded path parameters
Returns
the response

Implements anch::rest::Route.

◆ produces()

template<typename F>
template<typename C>
Endpoint & anch::rest::Endpoint< F >::produces ( )

Add a produced media type: result is serialized with codec C when it is negotiated

Template Parameters
Cthe codec (see anch::codec::Serializer )
Returns
this
Here is the call graph for this function:

◆ status()

template<typename F>
Endpoint & anch::rest::Endpoint< F >::status ( anch::rest::Status status)

Set success status: status of responses with serialized result ( 200 by default) or of void endpoints ( 204 by default), such as 201 or 202 . Endpoints which return anch::rest::Response set their status themselves, and empty std::optional results are still 404 .

Parameters
statusthe success status
Returns
this
Since
0.2
Here is the call graph for this function:

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