#include <restincurl.h>

Public Types | |
| using | ptr_t = std::unique_ptr<RequestBuilder> |
Public Member Functions | |
| RequestBuilder (Worker &worker) | |
| bool | CanSendFile () const noexcept |
Protected Member Functions | |
| RequestBuilder & | Prepare (RequestType rt, const std::string &url) |
Static Private Member Functions | |
| static size_t | write_callback (char *ptr, size_t size, size_t nitems, void *userdata) |
| static int | debug_callback (CURL *handle, curl_infotype type, char *data, size_t size, void *userp) |
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. | |||
| std::unique_ptr< Request > | request_ | ||
| std::unique_ptr< class Options > | options_ | ||
| std::string | url_ | ||
| RequestType | request_type_ = RequestType::INVALID | ||
| bool | have_data_in_ = false | ||
| bool | have_data_out_ = false | ||
| bool | is_built_ = false | ||
| completion_fn_t | completion_ | ||
| long | request_timeout_ = 10000L | ||
| long | connect_timeout_ = 3000L | ||
| Worker & | worker_ | ||
| 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.
Definition at line 1103 of file restincurl.h.
| using restincurl::RequestBuilder::ptr_t = std::unique_ptr<RequestBuilder> |
Definition at line 1148 of file restincurl.h.
|
inline |
Definition at line 1149 of file restincurl.h.
|
inline |
Definition at line 1161 of file restincurl.h.
|
inline |
Sets the accept header to "Application/json"
Definition at line 1272 of file restincurl.h.
References Header().
|
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.
Definition at line 1523 of file restincurl.h.
|
inline |
Definition at line 1561 of file restincurl.h.
|
inlinenoexcept |
Definition at line 1174 of file restincurl.h.
|
inline |
Set the connect timeout for a request
| timeout | Timeout in milliseconds. Set to -1 to use the default. |
Definition at line 1325 of file restincurl.h.
|
inlinestaticprivate |
Definition at line 1110 of file restincurl.h.
|
inline |
Use a HTTP DELETE request
Definition at line 1223 of file restincurl.h.
|
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.
Definition at line 1623 of file restincurl.h.
|
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).
Definition at line 1605 of file restincurl.h.
|
inline |
Use a HTTP GET request
Definition at line 1193 of file restincurl.h.
|
inline |
Use a HTTP HEAD request
Definition at line 1198 of file restincurl.h.
|
inline |
Specify a HTTP header for the request.
| value | The value of the header-line, properly formatted according to the relevant HTTP specifications. |
Definition at line 1237 of file restincurl.h.
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.
Definition at line 1251 of file restincurl.h.
References Header().
|
inline |
Do not process incoming data
The response body will be read from the network, but not buffered and not available for later inspection.
Definition at line 1489 of file restincurl.h.
|
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()
Definition at line 1288 of file restincurl.h.
Referenced by Trace().
|
inline |
Use a HTTP OPTIONS request
Definition at line 1228 of file restincurl.h.
|
inline |
Use a HTTP PATCH request
Definition at line 1218 of file restincurl.h.
|
inline |
Use a HTTP POST request
Definition at line 1203 of file restincurl.h.
|
inline |
Use a HTTP POST request
Definition at line 1208 of file restincurl.h.
|
inlineprotected |
Definition at line 1165 of file restincurl.h.
|
inline |
Use a HTTP PUT request
Definition at line 1213 of file restincurl.h.
|
inline |
Set request timeout
| timeout | Timeout in milliseconds. Set to -1 to use the default. |
Definition at line 1316 of file restincurl.h.
|
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).
Definition at line 1423 of file restincurl.h.
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).
Definition at line 1439 of file restincurl.h.
References 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 |
Definition at line 1337 of file restincurl.h.
|
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 |
Definition at line 1390 of file restincurl.h.
|
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 |
Definition at line 1370 of file restincurl.h.
|
inline |
Set a Curl compatible read handler.
| handler | Curl C API read handler |
You probably don't need to call this directly.
Definition at line 1541 of file restincurl.h.
|
inline |
Set a Curl compatible write handler.
| handler | Curl C API write handler |
You probably don't need to call this directly.
Definition at line 1554 of file restincurl.h.
|
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).
Definition at line 1458 of file restincurl.h.
Referenced by 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).
Definition at line 1475 of file restincurl.h.
References 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.
Definition at line 1301 of file restincurl.h.
References Option().
|
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.
Definition at line 1505 of file restincurl.h.
|
inline |
Sets the content-type to "Application/json; charset=utf-8"
Definition at line 1258 of file restincurl.h.
References Header().
Referenced by WithJson().
|
inline |
Sets the content-type to "Application/json; charset=utf-8"
| body | Json payload to send with the request. |
Definition at line 1266 of file restincurl.h.
References SendData(), and WithJson().
|
inlinestaticprivate |
Definition at line 1105 of file restincurl.h.
|
private |
Definition at line 1637 of file restincurl.h.
|
private |
Definition at line 1639 of file restincurl.h.
|
private |
Definition at line 1634 of file restincurl.h.
|
private |
Definition at line 1635 of file restincurl.h.
|
private |
Definition at line 1636 of file restincurl.h.
|
private |
Definition at line 1631 of file restincurl.h.
|
private |
Definition at line 1630 of file restincurl.h.
|
private |
Definition at line 1638 of file restincurl.h.
|
private |
Definition at line 1633 of file restincurl.h.
|
private |
Definition at line 1632 of file restincurl.h.
|
private |
Definition at line 1641 of file restincurl.h.