Request.hpp

This File On Github
Ask A Question

API: latest
module: oatpp
#include "oatpp/web/protocol/http/incoming/Request.hpp"

Request

Class http::incoming::Request AKA IncomingRequest represents client's incoming request.

namespace oatpp { namespace web { namespace protocol { namespace http { namespace incoming { 
  class Request : public oatpp::base::Countable {}
}}}}}

Methods

Return Type Name Summary
const http::QueryParams& getQueryParameters Get map of url query parameters.
oatpp::String getQueryParameter Multiple implementations:
  1. Get query parameter value by name
  2. Get query parameter value by name with defaultValue
const http::RequestStartingLine& getStartingLine Get request starting line. (method, path, protocol)
const url::mapping::Pattern::MatchMap& getPathVariables Get path variables according to path-pattern.
const http::Headers& getHeaders Get request's headers map
std::shared_ptr<oatpp::data::stream::InputStream> getBodyStream Get request's body stream
std::shared_ptr<const http::incoming::BodyDecoder> getBodyDecoder Get body decoder.
oatpp::String getHeader Get header value
oatpp::String getPathVariable Get path variable according to path-pattern
oatpp::String getPathTail Get path tail according to path-pattern
void streamBody Stream content of the body-stream to toStream
oatpp::String readBodyToString Transfer body stream to string
Type::ObjectWrapper readBodyToDto Multiple implementations:
  1. Transfer body to String and parse it as DTO
  2. Transfer body to String and parse it as DTO
oatpp::async::CoroutineStarter streamBodyAsync Transfer body stream to toStream Async
oatpp::async::CoroutineStarterForResult<const oatpp::String&> readBodyToStringAsync Transfer body stream to string Async.
oatpp::async::CoroutineStarterForResult<const typenameDtoType::ObjectWrapper&> readBodyToDtoAsync Transfer body to String and parse it as DTO

Request::getQueryParameters

Get map of url query parameters. Query parameters will be lazy parsed from url "tail" Please note: lazy parsing of query parameters is not thread-safe!

  • @return map<key, value> for "key=value"

const http::QueryParams& getQueryParameters() const

Request::getQueryParameter

  1. Get query parameter value by name
    • @param name
    • @return query parameter value
    oatpp::String getQueryParameter(const oatpp::data::share::StringKeyLabel& name) const
    
  2. Get query parameter value by name with defaultValue
    • @param name
    • @param defaultValue
    • @return query parameter value or defaultValue if no such parameter found
    oatpp::String getQueryParameter(const oatpp::data::share::StringKeyLabel& name, const oatpp::String& defaultValue) const
    

Request::getStartingLine

Get request starting line. (method, path, protocol)

  • @return starting line structure

const http::RequestStartingLine& getStartingLine() const

Request::getPathVariables

Get path variables according to path-pattern.
Ex. given request path="/sum/19/1" for path-pattern="/sum/{a}/{b}"
getPathVariables().getVariable("a") == 19, getPathVariables().getVariable("b") == 1.

  • @return url MatchMap

const url::mapping::Pattern::MatchMap& getPathVariables() const

Request::getHeaders

Get request's headers map

  • @return Headers map

const http::Headers& getHeaders() const

Request::getBodyStream

Get request's body stream

  • @return body stream

std::shared_ptr<oatpp::data::stream::InputStream> getBodyStream() const

Request::getBodyDecoder

Get body decoder.

  • @return Body decoder

std::shared_ptr<const http::incoming::BodyDecoder> getBodyDecoder() const

Request::getHeader

Get header value

  • @param headerName
  • @return header value

oatpp::String getHeader(const oatpp::data::share::StringKeyLabelCI_FAST& headerName) const

Request::getPathVariable

Get path variable according to path-pattern

  • @param name
  • @return matched value for path-pattern

oatpp::String getPathVariable(const oatpp::data::share::StringKeyLabel& name) const

Request::getPathTail

Get path tail according to path-pattern Ex. given request path="/hello/path/tail" for path-pattern="/hello/*" tail == "path/tail" note '/' symbol is required before '*'

  • @return matched tail-value for path-pattern

oatpp::String getPathTail() const

Request::streamBody

Stream content of the body-stream to toStream

  • @param toStream

void streamBody(const std::shared_ptr<oatpp::data::stream::OutputStream>& toStream) const

Request::readBodyToString

Transfer body stream to string

  • @return body as string

oatpp::String readBodyToString() const

Request::readBodyToDto

  1. Transfer body to String and parse it as DTO
    • @tparam Type
    • @param objectMapper
    • @return DTO
    template<class Type>
    typename Type::ObjectWrapper readBodyToDto(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const
    
  2. Transfer body to String and parse it as DTO (used in ApiController's codegens)
    • @tparam Type
    • @param objectMapper
    • @return DTO
    template<class Type>
    void readBodyToDto(oatpp::data::mapping::type::PolymorphicWrapper<Type>& objectWrapper,
                       const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const
    

Request::streamBodyAsync

Transfer body stream to toStream Async

oatpp::async::CoroutineStarter streamBodyAsync(const std::shared_ptr<oatpp::data::stream::OutputStream>& toStream) const

Request::readBodyToStringAsync

Transfer body stream to string Async.

  • @return - oatpp::async::CoroutineStarterForResult.

oatpp::async::CoroutineStarterForResult<const oatpp::String&> readBodyToStringAsync() const

Request::readBodyToDtoAsync

Transfer body to String and parse it as DTO

  • @tparam DtoType - DTO object type.
  • @param objectMapper
  • @return - oatpp::async::CoroutineStarterForResult.

template<class DtoType>
oatpp::async::CoroutineStarterForResult<const typename DtoType::ObjectWrapper&>
readBodyToDtoAsync(const std::shared_ptr<oatpp::data::mapping::ObjectMapper>& objectMapper) const