#include <endpoint.hpp>
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 > ¶meters) 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 |
Endpoint function bound to a route.
Function arguments are, in order:
400 when invalid)Content-Type (415 when not consumed, 400 when missing or invalid)Content-Type is (absent included, no codec: read it with const Request& ), empty without bodyFunction result:
void : 204 std::optional<T> : 404 when empty, T otherwiseT : serialized with the codec negotiated with Accept (406 when not acceptable)| F | the function type |
| anch::rest::Endpoint< F >::Endpoint | ( | anch::rest::Method | method, |
| std::string | pattern, | ||
| std::vector< std::string > | parameterNames, | ||
| F | function ) |
Endpoint constructor
| method | the method |
| pattern | the path pattern |
| parameterNames | the path parameter names |
| function | the endpoint function |
|
overridevirtual |
Check endpoint configuration: a serialized result needs a produced media type, a body needs a consumed media type
Implements anch::rest::Route.
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)
| C | the codec (see anch::codec::Deserializer ) |
this
|
overridevirtualnoexcept |
Get the number of path parameters expected by endpoint
Implements anch::rest::Route.
|
overridevirtual |
Execute endpoint
| request | the request |
| parameters | the decoded path parameters |
Implements anch::rest::Route.
Add a produced media type: result is serialized with codec C when it is negotiated
| C | the codec (see anch::codec::Serializer ) |
this | 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 .
| status | the success status |
this