AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::rest::Request Class Reference

#include <request.hpp>

Collaboration diagram for anch::rest::Request:

Public Member Functions

 Request ()
 Request (anch::rest::Method method, std::string_view target)
void setTarget (std::string_view target)
std::optional< std::string_view > getQueryParameter (std::string_view name) const
void addQueryParameter (std::string_view name, std::string_view value)
std::optional< std::string_view > getPathParameter (std::string_view name) const
std::optional< anch::codec::MediaType > getContentType () const
std::vector< anch::codec::MediaType > getAccept () const
bool hasBody () const noexcept
std::istream & getBody () const
void setBody (std::unique_ptr< std::istream > body)
void setBody (std::string body)
anch::rest::Method getMethod () const noexcept
void setMethod (anch::rest::Method method) noexcept
const std::string & getPath () const noexcept
void setPath (std::string_view path)
const std::vector< std::pair< std::string, std::string > > & getQueryParameters () const noexcept
anch::rest::Headers & getHeaders () noexcept
const anch::rest::Headers & getHeaders () const noexcept
const std::map< std::string, std::string, std::less<> > & getPathParameters () const noexcept
void setPathParameters (std::map< std::string, std::string, std::less<> > parameters)

Detailed Description

HTTP request.
The path is kept percent-encoded (path parameters are decoded by the router); query parameters are decoded.
The request owns its body stream: it can be moved, not copied.

Author
Vincent Lachenal
Since
0.2

Constructor & Destructor Documentation

◆ Request() [1/2]

anch::rest::Request::Request ( )

Request default constructor: GET /

◆ Request() [2/2]

anch::rest::Request::Request ( anch::rest::Method method,
std::string_view target )

Request constructor

Parameters
methodthe method
targetthe request target (path and query, /pets?limit=10 )

Member Function Documentation

◆ addQueryParameter()

void anch::rest::Request::addQueryParameter ( std::string_view name,
std::string_view value )

Add a query parameter

Parameters
namethe parameter name
valuethe parameter value

◆ getAccept()

std::vector< anch::codec::MediaType > anch::rest::Request::getAccept ( ) const

Get Accept header media ranges (see anch::codec::MediaType::parseAccept )

Returns
the media ranges, empty when header is not set

◆ getBody()

std::istream & anch::rest::Request::getBody ( ) const

Get body stream. Request must have a body (hasBody ).

Returns
the body stream
Here is the call graph for this function:

◆ getContentType()

std::optional< anch::codec::MediaType > anch::rest::Request::getContentType ( ) const

Get Content-Type header

Returns
the content type, empty when header is not set or invalid

◆ getHeaders() [1/2]

const anch::rest::Headers & anch::rest::Request::getHeaders ( ) const
noexcept

Headers getter

Returns
the headers
Here is the call graph for this function:

◆ getHeaders() [2/2]

anch::rest::Headers & anch::rest::Request::getHeaders ( )
noexcept

Headers getter

Returns
the headers
Here is the call graph for this function:

◆ getMethod()

anch::rest::Method anch::rest::Request::getMethod ( ) const
noexcept

Method getter

Returns
the method
Here is the call graph for this function:

◆ getPath()

const std::string & anch::rest::Request::getPath ( ) const
noexcept

Path getter

Returns
the percent-encoded path
Here is the call graph for this function:

◆ getPathParameter()

std::optional< std::string_view > anch::rest::Request::getPathParameter ( std::string_view name) const

Get path parameter value

Parameters
namethe parameter name
Returns
the value, empty when parameter does not exist

◆ getPathParameters()

const std::map< std::string, std::string, std::less<> > & anch::rest::Request::getPathParameters ( ) const
noexcept

Path parameters getter

Returns
the path parameters
Here is the call graph for this function:

◆ getQueryParameter()

std::optional< std::string_view > anch::rest::Request::getQueryParameter ( std::string_view name) const

Get query parameter first value

Parameters
namethe parameter name
Returns
the value, empty when parameter is not set

◆ getQueryParameters()

const std::vector< std::pair< std::string, std::string > > & anch::rest::Request::getQueryParameters ( ) const
noexcept

Query parameters getter

Returns
the decoded query parameters
Here is the call graph for this function:

◆ hasBody()

bool anch::rest::Request::hasBody ( ) const
noexcept

Check if request has a body

Returns
true when request has a body

◆ setBody() [1/2]

void anch::rest::Request::setBody ( std::string body)

Set body content

Parameters
bodythe body content
Here is the call graph for this function:

◆ setBody() [2/2]

void anch::rest::Request::setBody ( std::unique_ptr< std::istream > body)

Set body stream

Parameters
bodythe body stream
Here is the call graph for this function:

◆ setMethod()

void anch::rest::Request::setMethod ( anch::rest::Method method)
noexcept

Method setter

Parameters
methodthe method
Here is the call graph for this function:

◆ setPath()

void anch::rest::Request::setPath ( std::string_view path)

Path setter

Parameters
paththe percent-encoded path
Here is the call graph for this function:

◆ setPathParameters()

void anch::rest::Request::setPathParameters ( std::map< std::string, std::string, std::less<> > parameters)

Path parameters setter

Parameters
parametersthe path parameters
Here is the call graph for this function:

◆ setTarget()

void anch::rest::Request::setTarget ( std::string_view target)

Set path and query parameters from request target (/pets?limit=10 )

Parameters
targetthe request target

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