mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-06-01 01:54:00 +00:00
49 lines
1.5 KiB
C++
49 lines
1.5 KiB
C++
/**
|
|
* @file web_client/http_web_client.h
|
|
* @brief cpp-httplib implementation of the WebClient interface.
|
|
*/
|
|
|
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_HTTP_WEB_CLIENT_CURL_WEB_CLIENT_H_
|
|
#define BIERGARTEN_PIPELINE_INCLUDES_HTTP_WEB_CLIENT_CURL_WEB_CLIENT_H_
|
|
|
|
|
|
#include "web_client/web_client.h"
|
|
|
|
#include <string>
|
|
|
|
/**
|
|
* @brief WebClient implementation backed by cpp-httplib.
|
|
*
|
|
* Supports HTTP and HTTPS (requires
|
|
* OpenSSL; see HTTPLIB_USE_OPENSSL_IF_AVAILABLE in CMakeLists.txt).
|
|
*
|
|
* URL parsing splits a full URL into scheme + host and path + query so that
|
|
* httplib::Client can be constructed correctly. A new client instance is
|
|
* created per request; th is is intentional given the low call volume in the
|
|
* pipeline (Wikipedia enrichment, near-100 % cache hits).
|
|
*/
|
|
class HttpWebClient final : public WebClient {
|
|
public:
|
|
HttpWebClient() = default;
|
|
~HttpWebClient() override = default;
|
|
|
|
/**
|
|
* @brief Executes a blocking HTTP/HTTPS GET request against a full URL.
|
|
*
|
|
* @param url Fully-qualified URL, e.g. "https://en.wikipedia.org/api/rest_v1/page/summary/Berlin"
|
|
* @return Response body on HTTP 2xx; throws std::runtime_error otherwise.
|
|
*/
|
|
std::string Get(const std::string& url) override;
|
|
|
|
/**
|
|
* @brief Percent-encodes a single URI component (query parameter value or
|
|
* path segment). Delegates to httplib::encode_uri_component().
|
|
*
|
|
* @param value Raw string to encode.
|
|
* @return Percent-encoded string safe for use in a URL.
|
|
*/
|
|
std::string UrlEncode(const std::string& value) override;
|
|
};
|
|
|
|
|
|
#endif |