#include <restincurl.h>

Public Types | |
| using | ptr_t = std::unique_ptr<RequestBuilder> |
Public Member Functions | |
| RequestBuilder (Worker &worker) | |
| ~RequestBuilder () | |
| bool | CanSendFile () const noexcept |
Protected Member Functions | |
| RequestBuilder & | Prepare (RequestType rt, const std::string &url) |
Type of request | |||
Use one of these functions to declare what HTTP request you want to use.
Note that you must use only only one of these methods in one request. | |||
| RequestBuilder & | Get (const std::string &url) | ||
| RequestBuilder & | Head (const std::string &url) | ||
| RequestBuilder & | Post (const std::string &url) | ||
| RequestBuilder & | PostMime (const std::string &url) | ||
| RequestBuilder & | Put (const std::string &url) | ||
| RequestBuilder & | Patch (const std::string &url) | ||
| RequestBuilder & | Delete (const std::string &url) | ||
| RequestBuilder & | Options (const std::string &url) | ||
| RequestBuilder & | Header (const char *value) | ||
| RequestBuilder & | Header (const std::string &name, const std::string &value) | ||
| RequestBuilder & | WithJson () | ||
| RequestBuilder & | WithJson (std::string body) | ||
| RequestBuilder & | AcceptJson () | ||
| template<typename T> | |||
| RequestBuilder & | Option (const CURLoption &opt, const T &value) | ||
| RequestBuilder & | Trace (bool enable=true) | ||
| RequestBuilder & | RequestTimeout (const long timeout) | ||
| RequestBuilder & | ConnectTimeout (const long timeout) | ||
| RequestBuilder & | SendFile (const std::string &path) | ||
| RequestBuilder & | SendFileAsMimeData (const std::string &path, const std::string &name={}, const std::string &remoteName={}, const std::string &mimeType={}) | ||
| RequestBuilder & | SendFileAsForm (const std::string &path) | ||
| template<typename T> | |||
| RequestBuilder & | SendData (OutDataHandler< T > &dh) | ||
| template<typename T> | |||
| RequestBuilder & | SendData (T data) | ||
| template<typename T> | |||
| RequestBuilder & | StoreData (InDataHandler< T > &dh) | ||
| template<typename T> | |||
| RequestBuilder & | StoreData (T &data) | ||
| RequestBuilder & | IgnoreIncomingData () | ||
| RequestBuilder & | WithCompletion (completion_fn_t fn) | ||
| RequestBuilder & | BasicAuthentication (const std::string &name, const std::string &passwd) | ||
| RequestBuilder & | SetReadHandler (size_t(*handler)(char *, size_t, size_t, void *), void *userdata) | ||
| RequestBuilder & | SetWriteHandler (size_t(*handler)(char *, size_t, size_t, void *), void *userdata) | ||
| void | Build () | ||
| void | ExecuteSynchronous () | ||
| void | Execute () | ||
Convenient interface to build requests.
Even if this is a light-weight wrapper around libcurl, we have a simple and modern way to define our requests that contains convenience-methods for the most common use-cases.
| using restincurl::RequestBuilder::ptr_t = std::unique_ptr<RequestBuilder> |
|
inline |
References Options(), and RESTINCURL_ENABLE_ASYNC.
Referenced by AcceptJson(), BasicAuthentication(), ConnectTimeout(), Delete(), Get(), Head(), Header(), Header(), IgnoreIncomingData(), Option(), Options(), Patch(), Post(), PostMime(), Prepare(), Put(), RequestTimeout(), SendData(), SendData(), SendFile(), SendFileAsForm(), SendFileAsMimeData(), SetReadHandler(), SetWriteHandler(), StoreData(), StoreData(), Trace(), WithCompletion(), WithJson(), and WithJson().
|
inline |
|
inline |
Sets the accept header to "Application/json"
References Header(), and RequestBuilder().
|
inline |
HTTP Basic Authentication
Authenticate the request with HTTP Basic Authentication.
| name | Name to authenticate with |
| passwd | Password to authenticate with |
Note that if name or password is empty, authentication is ignored. This makes it simple to add optional authentication to your project, by simply assigning values to the strings you pass here, or not.
References RequestBuilder().
|
inline |
References RESTINCURL_LOG, and StoreData().
Referenced by Execute(), and ExecuteSynchronous().
|
inlinenoexcept |
References restincurl::POST, and restincurl::PUT.
Referenced by SendFile(), and SendFileAsForm().
|
inline |
Set the connect timeout for a request
| timeout | Timeout in milliseconds. Set to -1 to use the default. |
References RequestBuilder().
|
inline |
Use a HTTP DELETE request
References restincurl::DELETE, Prepare(), and RequestBuilder().
|
inline |
Execute the request asynchronously
This will queue the request for processing. If the number of active requests are less than RESTINCURL_MAX_CONNECTIONS, the request will start executing almost immediately.
The method returns immediately.
| restincurl::Exception | derived exceptions on error |
This method is only available when RESTINCURL_ENABLE_ASYNC is nonzero.
References Build().
|
inline |
Execute the request synchronously
This will execute the request and call the callback (if you declared one) in the current thread before the method returns.
| restincurl::Exception | derived exceptions on error |
This method is available even when RESTINCURL_ENABLE_ASYNC is enabled ( != 0).
References Build().
|
inline |
Use a HTTP GET request
References restincurl::GET, Prepare(), and RequestBuilder().
|
inline |
Use a HTTP HEAD request
References restincurl::HEAD, Prepare(), and RequestBuilder().
|
inline |
Specify a HTTP header for the request.
| value | The value of the header-line, properly formatted according to the relevant HTTP specifications. |
References RequestBuilder().
Referenced by AcceptJson(), Header(), and WithJson().
|
inline |
Specify a HTTP header for the request.
| name | Name of the header |
| value | The value of the header |
This is a convenience method that will build the appropriate header for you.
References Header(), and RequestBuilder().
|
inline |
Do not process incoming data
The response body will be read from the network, but not buffered and not available for later inspection.
References RequestBuilder().
|
inline |
Sets a Curl options.
| opt | CURLoption enum specifying the option |
| value | Value to set. |
It is critical that the type of the value is of the same type that libcurl is expecting for the option. RESTinCurl makes no attempt to validate or cast the values.
Please refer to the libcurl documentation for curl_easy_setopt()
References RequestBuilder().
Referenced by Trace().
|
inline |
Use a HTTP OPTIONS request
References restincurl::OPTIONS, Prepare(), and RequestBuilder().
Referenced by RequestBuilder().
|
inline |
Use a HTTP PATCH request
References restincurl::PATCH, Prepare(), and RequestBuilder().
|
inline |
Use a HTTP POST request
References restincurl::POST, Prepare(), and RequestBuilder().
|
inline |
Use a HTTP POST request
References restincurl::POST_MIME, Prepare(), and RequestBuilder().
|
inlineprotected |
References restincurl::INVALID, and RequestBuilder().
Referenced by Delete(), Get(), Head(), Options(), Patch(), Post(), PostMime(), and Put().
|
inline |
Use a HTTP PUT request
References Prepare(), restincurl::PUT, and RequestBuilder().
|
inline |
Set request timeout
| timeout | Timeout in milliseconds. Set to -1 to use the default. |
References RequestBuilder().
|
inline |
Specify Data Handler for outbound data
You can use this method when you need to use a Data Handler, rather than a simple string, to provide the data for a POST, PUT etc. request.
| dh | Data Handler instance. |
Note that the Data Handler is passed by reference. It is your responsibility that the instance is present at least until the request has finished (your code owns the Data Handler instance).
References restincurl::OutDataHandler< T >::read_callback(), and RequestBuilder().
Referenced by SendData(), and WithJson().
|
inline |
Convenience method to specify a object that contains the data to send during a request.
| data | Data to send. Typically this will be a std::string, std::vector<char> or a similar object. |
RESTinCurl takes ownership of this data (by moving it).
References RequestBuilder(), and SendData().
|
inline |
Send a file
| path | Full path to the file to send. |
| SystemException | if the file cannot be opened. |
| Exception | if the method is called for a non-send operation |
References CanSendFile(), errno, and RequestBuilder().
|
inline |
Send a file
| path | Full path to the file to send. |
| SystemException | if the file cannot be opened. |
| Exception | if the method is called for a non-send operation |
References CanSendFile(), errno, and RequestBuilder().
|
inline |
Send a file as a multipart/form mime segment
| path | Full path to the file tro send |
| name | Otional name to use for the file in the mime segment |
| remoteName | Optional name to label the file as for the remote end |
| mimeType | Optional mime-type for the file |
| Exception | if the method is called for a non-mime-post operation |
References RequestBuilder().
|
inline |
Set a Curl compatible read handler.
| handler | Curl C API read handler |
You probably don't need to call this directly.
References RequestBuilder().
|
inline |
Set a Curl compatible write handler.
| handler | Curl C API write handler |
You probably don't need to call this directly.
References RequestBuilder().
|
inline |
Specify Data Handler for inbound data
You can use this method when you need to use a Data Handler, rather than a simple string, to receive data during the request.
| dh | Data Handler instance. |
Note that the Data Handler is passed by reference. It is your responsibility that the instance is present at least until the request has finished (your code owns the Data Handler instance).
References RequestBuilder(), and restincurl::InDataHandler< T >::write_callback().
Referenced by Build(), and StoreData().
|
inline |
Convenience method to specify a object that receives incoming data during a request.
| data | Buffer to hold incoming data. Typically this will be a std::string, std::vector<char> or a similar object. |
Note that data is passed by reference. It is your responsibility that the instance is present at least until the request has finished (your code owns the object).
References RequestBuilder(), and StoreData().
|
inline |
Enables or disables trace logging for requests.
The trace logging will show detailed information about what libcurl does and data sent and received during a request.
Basically it sets CURLOPT_DEBUGFUNCTION and CURLOPT_VERBOSE.
References Option(), and RequestBuilder().
|
inline |
Specify a callback that will be called when the request is complete (or failed).
| fn | Callback to be called |
For asynchronous requests, the callback will be called from the worker-thread shared by all requests and timers for the client instance. It is imperative that you return immediately, and don't keep the thread busy more than strictly required. If you need do do some computing or IO in response to the information you receive, you should do that in another thread.
References RequestBuilder().
|
inline |
Sets the content-type to "Application/json; charset=utf-8"
References Header(), and RequestBuilder().
Referenced by WithJson().
|
inline |
Sets the content-type to "Application/json; charset=utf-8"
| body | Json payload to send with the request. |
References RequestBuilder(), SendData(), and WithJson().