C++ edjLibrary SDK
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
edjx::fetch::HttpFetch Struct Reference

An HTTP fetch request includes body, headers, version, method, and URI. More...

#include <fetch.hpp>

Public Member Functions

 HttpFetch (http::Uri uri, http::HttpMethod method)
 Creates a request with the given method and URI, version as HTTP/1.1, no headers, and no body. More...
 
HttpFetchset_version (http::HttpVersion version)
 Sets the HTTP version of the request. More...
 
http::HttpVersion get_version () const
 Gets the HTTP version of the request. More...
 
HttpFetchset_header (const std::string &header_name, const std::string &value)
 Sets a request header to the given value. More...
 
HttpFetchset_header (const std::string &header_name, const std::vector< std::string > &value)
 Sets a request header to the given values. More...
 
HttpFetchappend_header (const std::string &header_name, const std::string &value)
 Appends a value to the existing request header. More...
 
HttpFetchset_headers (const edjx::http::HttpHeaders &value)
 Set request headers to the given values. More...
 
const edjx::http::HttpHeadersget_headers () const
 Returns a const reference to the request header map. More...
 
HttpFetchset_body (const std::string &text)
 Sets the given [text] value as the body of the request. More...
 
HttpFetchset_body (const std::vector< std::uint8_t > bytes)
 Sets the given [bytes] value as the body of the request. More...
 
const std::vector< uint8_t > & get_body () const
 Returns a constant reference to the body. More...
 
edjx::error::HttpError send (FetchResponse &response)
 Sends the request to the server, and returns after the response is received or an error occurs. More...
 
edjx::error::HttpError send_streaming (FetchResponsePending &response, edjx::stream::WriteStream &write_stream)
 Starts streaming an HTTP Fetch request to the server. This method returns a FetchResponsePending object and an edjx::stream::WriteStream object. The edjx::stream::WriteStream object is used to stream data. The FetchResponsePending is a placeholder to retreive FetchResponse. In the background, this method triggers sending HTTP headers and other HTTP artifacts to the server. More...
 

Public Attributes

http::HttpVersion version
 HTTP version of the request. More...
 
edjx::http::HttpHeaders headers
 Headers for the request. More...
 
http::Uri uri
 URI of the request. More...
 
http::HttpMethod method
 Method for the request. More...
 
std::vector< uint8_t > body
 Request body. More...
 

Detailed Description

An HTTP fetch request includes body, headers, version, method, and URI.

Constructor & Destructor Documentation

◆ HttpFetch()

edjx::fetch::HttpFetch::HttpFetch ( http::Uri  uri,
http::HttpMethod  method 
)
inline

Creates a request with the given method and URI, version as HTTP/1.1, no headers, and no body.

Parameters
uriRequest URI
methodRequest method

Member Function Documentation

◆ append_header()

HttpFetch & edjx::fetch::HttpFetch::append_header ( const std::string &  header_name,
const std::string &  value 
)

Appends a value to the existing request header.

Keeps any previous values for the given header name.

Parameters
header_nameHeader name
valueHeader value
Returns
Reference to this HttpFetch object

◆ get_body()

const std::vector< uint8_t > & edjx::fetch::HttpFetch::get_body ( ) const

Returns a constant reference to the body.

Returns
Request body

◆ get_headers()

const edjx::http::HttpHeaders & edjx::fetch::HttpFetch::get_headers ( ) const

Returns a const reference to the request header map.

Returns
Request headers

◆ get_version()

http::HttpVersion edjx::fetch::HttpFetch::get_version ( ) const

Gets the HTTP version of the request.

Returns
HTTP version of the request

◆ send()

edjx::error::HttpError edjx::fetch::HttpFetch::send ( FetchResponse response)

Sends the request to the server, and returns after the response is received or an error occurs.

Parameters
response
Returns
Returns edjx::error::HttpError::Success on success, some other value on failure.

◆ send_streaming()

edjx::error::HttpError edjx::fetch::HttpFetch::send_streaming ( FetchResponsePending response,
edjx::stream::WriteStream write_stream 
)

Starts streaming an HTTP Fetch request to the server. This method returns a FetchResponsePending object and an edjx::stream::WriteStream object. The edjx::stream::WriteStream object is used to stream data. The FetchResponsePending is a placeholder to retreive FetchResponse. In the background, this method triggers sending HTTP headers and other HTTP artifacts to the server.

This method and the send() method cannot be used together.

Parameters
responseA placeholder for the server's response will be copied to this object. It can retreive the server's response once the response is received.
write_streamA write stream for streaming the HTTP Fetch request body.
Returns
Returns edjx::error::HttpError::Success on success, some other value on failure.

◆ set_body() [1/2]

HttpFetch & edjx::fetch::HttpFetch::set_body ( const std::string &  text)

Sets the given [text] value as the body of the request.

Any body that was previously set on the request is discarded.

Parameters
textString to be used as the body
Returns
Reference to this HttpFetch object

◆ set_body() [2/2]

HttpFetch & edjx::fetch::HttpFetch::set_body ( const std::vector< std::uint8_t >  bytes)

Sets the given [bytes] value as the body of the request.

Any body that was previously set on the request is discarded.

Parameters
bytesBytes to be used as the body
Returns
Reference to this HttpFetch object

◆ set_header() [1/2]

HttpFetch & edjx::fetch::HttpFetch::set_header ( const std::string &  header_name,
const std::string &  value 
)

Sets a request header to the given value.

Discards any previous values for the given header name.

Parameters
header_nameHeader name
valueHeader value
Returns
Reference to this HttpFetch object

◆ set_header() [2/2]

HttpFetch & edjx::fetch::HttpFetch::set_header ( const std::string &  header_name,
const std::vector< std::string > &  value 
)

Sets a request header to the given values.

Discards any previous values for the given header name.

Parameters
header_nameHeader name
valueHeader values
Returns
Reference to this HttpFetch object

◆ set_headers()

HttpFetch & edjx::fetch::HttpFetch::set_headers ( const edjx::http::HttpHeaders value)

Set request headers to the given values.

All previously defined headers will be discarded.

Parameters
valueHTTP headers
Returns
Reference to this HttpFetch object

◆ set_version()

HttpFetch & edjx::fetch::HttpFetch::set_version ( http::HttpVersion  version)

Sets the HTTP version of the request.

Parameters
versionVersion to be set
Returns
Reference to this HttpFetch object

Member Data Documentation

◆ body

std::vector<uint8_t> edjx::fetch::HttpFetch::body

Request body.

◆ headers

edjx::http::HttpHeaders edjx::fetch::HttpFetch::headers

Headers for the request.

◆ method

http::HttpMethod edjx::fetch::HttpFetch::method

Method for the request.

◆ uri

http::Uri edjx::fetch::HttpFetch::uri

URI of the request.

◆ version

http::HttpVersion edjx::fetch::HttpFetch::version

HTTP version of the request.


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