Add HTTP methods PATCH and PUT.
This commit is contained in:
parent
5051664136
commit
f556df296f
|
@ -161,6 +161,58 @@ public:
|
||||||
return post(endpoint, {});
|
return post(endpoint, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Make a HTTP PATCH call with parameters.
|
||||||
|
*
|
||||||
|
* @param endpoint Endpoint as API::endpoint_type or `std::string_view`.
|
||||||
|
* @param parameters A map of parameters.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
answer_type patch(const endpoint_variant &endpoint,
|
||||||
|
const parametermap ¶meters);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Make a HTTP PATCH call.
|
||||||
|
*
|
||||||
|
* @param endpoint Endpoint as API::endpoint_type or `std::string_view`.
|
||||||
|
*
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
inline answer_type patch(const endpoint_variant &endpoint)
|
||||||
|
{
|
||||||
|
return post(endpoint, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Make a HTTP PUT call with parameters.
|
||||||
|
*
|
||||||
|
* @param endpoint Endpoint as API::endpoint_type or `std::string_view`.
|
||||||
|
* @param parameters A map of parameters.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
answer_type put(const endpoint_variant &endpoint,
|
||||||
|
const parametermap ¶meters);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Make a HTTP PUT call.
|
||||||
|
*
|
||||||
|
* @param endpoint Endpoint as API::endpoint_type or `std::string_view`.
|
||||||
|
*
|
||||||
|
* @since 0.1.0
|
||||||
|
*/
|
||||||
|
[[nodiscard]]
|
||||||
|
inline answer_type put(const endpoint_variant &endpoint)
|
||||||
|
{
|
||||||
|
return post(endpoint, {});
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Copy new stream contents and delete the “original”.
|
* @brief Copy new stream contents and delete the “original”.
|
||||||
*
|
*
|
||||||
|
|
|
@ -61,6 +61,20 @@ answer_type Connection::post(const endpoint_variant &endpoint,
|
||||||
endpoint_to_uri(endpoint), parameters);
|
endpoint_to_uri(endpoint), parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
answer_type Connection::patch(const endpoint_variant &endpoint,
|
||||||
|
const parametermap ¶meters)
|
||||||
|
{
|
||||||
|
return make_request(http_method::PATCH,
|
||||||
|
endpoint_to_uri(endpoint), parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
answer_type Connection::put(const endpoint_variant &endpoint,
|
||||||
|
const parametermap ¶meters)
|
||||||
|
{
|
||||||
|
return make_request(http_method::PUT,
|
||||||
|
endpoint_to_uri(endpoint), parameters);
|
||||||
|
}
|
||||||
|
|
||||||
string Connection::get_new_stream_contents()
|
string Connection::get_new_stream_contents()
|
||||||
{
|
{
|
||||||
buffer_mutex.lock();
|
buffer_mutex.lock();
|
||||||
|
|
|
@ -111,14 +111,30 @@ answer_type CURLWrapper::make_request(const http_method &method, string uri,
|
||||||
}
|
}
|
||||||
case http_method::PATCH:
|
case http_method::PATCH:
|
||||||
{
|
{
|
||||||
|
if (!parameters.empty())
|
||||||
|
{
|
||||||
|
curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
|
code = curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
|
||||||
|
}
|
||||||
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST, "PATCH");
|
code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST, "PATCH");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case http_method::PUT:
|
case http_method::PUT:
|
||||||
{
|
{
|
||||||
|
if (!parameters.empty())
|
||||||
|
{
|
||||||
|
curl_mime *mime{parameters_to_curl_mime(uri, parameters)};
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
|
code = curl_easy_setopt(_connection, CURLOPT_MIMEPOST, mime);
|
||||||
|
}
|
||||||
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
code = curl_easy_setopt(_connection, CURLOPT_UPLOAD, 1L);
|
code = curl_easy_setopt(_connection, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case http_method::DELETE:
|
case http_method::DELETE:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user