#include <client.hpp>
Public Member Functions | |
| Client (std::unique_ptr< anch::rest::Transport > transport, std::string_view baseUrl) | |
| Client & | header (std::string_view name, std::string_view value) |
| Client & | filter (anch::rest::Filter filter) |
| template<anch::rest::ParameterValue... P> | |
| anch::rest::Call | request (anch::rest::Method method, std::string_view path, const P &... parameters) |
| template<anch::rest::ParameterValue... P> | |
| anch::rest::Call | get (std::string_view path, const P &... parameters) |
| template<anch::rest::ParameterValue... P> | |
| anch::rest::Call | post (std::string_view path, const P &... parameters) |
| template<anch::rest::ParameterValue... P> | |
| anch::rest::Call | put (std::string_view path, const P &... parameters) |
| template<anch::rest::ParameterValue... P> | |
| anch::rest::Call | patch (std::string_view path, const P &... parameters) |
| template<anch::rest::ParameterValue... P> | |
| anch::rest::Call | del (std::string_view path, const P &... parameters) |
| template<anch::rest::ParameterValue... P> | |
| anch::rest::Call | head (std::string_view path, const P &... parameters) |
| anch::rest::Response | send (anch::rest::Request &request) |
| std::string | url (const anch::rest::Request &request) const |
Static Public Member Functions | |
| static std::string | formatPath (std::string_view path, const std::vector< std::string > ¶meters) |
HTTP client: builds requests and sends them through a Transport .
Path parameters ({name} placeholders) are replaced in order and percent-encoded.
Default headers (User-Agent is anch-rest ) are set when the request does not set them, then filters are executed in declaration order before the transport.
A client is as thread safe as its transport.
| anch::rest::Client::Client | ( | std::unique_ptr< anch::rest::Transport > | transport, |
| std::string_view | baseUrl ) |
Client constructor
| transport | the transport |
| baseUrl | the base URL (https://api.example.com/v1 ) |
| anch::rest::Call anch::rest::Client::del | ( | std::string_view | path, |
| const P &... | parameters ) |
Start a DELETE request (see request )
| path | the path |
| parameters | the path parameters |
| Client & anch::rest::Client::filter | ( | anch::rest::Filter | filter | ) |
Add filter
| filter | the filter |
this
|
static |
Replace path placeholders ({name} ) with percent-encoded parameters
| path | the path |
| parameters | the parameters, in placeholders order |
| std::invalid_argument | when the number of parameters does not match placeholders |
| anch::rest::Call anch::rest::Client::get | ( | std::string_view | path, |
| const P &... | parameters ) |
Start a GET request (see request )
| path | the path |
| parameters | the path parameters |
| anch::rest::Call anch::rest::Client::head | ( | std::string_view | path, |
| const P &... | parameters ) |
Start a HEAD request (see request )
| path | the path |
| parameters | the path parameters |
| Client & anch::rest::Client::header | ( | std::string_view | name, |
| std::string_view | value ) |
Set default header
| name | the header name |
| value | the header value |
this | anch::rest::Call anch::rest::Client::patch | ( | std::string_view | path, |
| const P &... | parameters ) |
Start a PATCH request (see request )
| path | the path |
| parameters | the path parameters |
| anch::rest::Call anch::rest::Client::post | ( | std::string_view | path, |
| const P &... | parameters ) |
Start a POST request (see request )
| path | the path |
| parameters | the path parameters |
| anch::rest::Call anch::rest::Client::put | ( | std::string_view | path, |
| const P &... | parameters ) |
Start a PUT request (see request )
| path | the path |
| parameters | the path parameters |
| anch::rest::Call anch::rest::Client::request | ( | anch::rest::Method | method, |
| std::string_view | path, | ||
| const P &... | parameters ) |
Start a request
| method | the method |
| path | the path relative to base URL, with {name} placeholders |
| parameters | the path parameters, in placeholders order |
| std::invalid_argument | when the number of parameters does not match placeholders |
| anch::rest::Response anch::rest::Client::send | ( | anch::rest::Request & | request | ) |
Send request: default headers, filters, then transport
| request | the request |
| anch::rest::TransportError | when request fails |
| std::string anch::rest::Client::url | ( | const anch::rest::Request & | request | ) | const |
Get request URL: base URL, path and encoded query parameters
| request | the request |