iceberg-cpp
Loading...
Searching...
No Matches
http_client.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <chrono>
23#include <cstdint>
24#include <memory>
25#include <string>
26#include <unordered_map>
27
30#include "iceberg/result.h"
31
34
35namespace cpr {
36class ConnectionPool;
37} // namespace cpr
38
39namespace iceberg::rest {
40
46class ICEBERG_REST_EXPORT HttpResponse {
47 public:
49 HttpResponse(int32_t status_code, std::string body);
51
52 HttpResponse(const HttpResponse&) = delete;
53 HttpResponse& operator=(const HttpResponse&) = delete;
54 HttpResponse(HttpResponse&&) noexcept;
55 HttpResponse& operator=(HttpResponse&&) noexcept;
56
58 int32_t status_code() const;
59
61 std::string body() const;
62
64 std::unordered_map<std::string, std::string> headers() const;
65
66 private:
67 friend class HttpClient;
68 class Impl;
69 std::unique_ptr<Impl> impl_;
70};
71
73class ICEBERG_REST_EXPORT HttpClient {
74 public:
76 explicit HttpClient(std::unordered_map<std::string, std::string> default_headers = {},
77 std::chrono::milliseconds connection_timeout = {},
78 std::chrono::milliseconds socket_timeout = {},
79 std::optional<std::string> base_uri = std::nullopt);
80 virtual ~HttpClient();
81
82 HttpClient(const HttpClient&) = delete;
83 HttpClient& operator=(const HttpClient&) = delete;
84 HttpClient(HttpClient&&) = delete;
85 HttpClient& operator=(HttpClient&&) = delete;
86
89 const std::string& path, const std::unordered_map<std::string, std::string>& params,
90 const std::unordered_map<std::string, std::string>& headers,
91 const ErrorHandler& error_handler, auth::AuthSession& session);
92
95 const std::string& path, const std::string& body,
96 const std::unordered_map<std::string, std::string>& headers,
97 const ErrorHandler& error_handler, auth::AuthSession& session);
98
101 const std::string& path,
102 const std::unordered_map<std::string, std::string>& form_data,
103 const std::unordered_map<std::string, std::string>& headers,
104 const ErrorHandler& error_handler, auth::AuthSession& session);
105
108 const std::string& path,
109 const std::unordered_map<std::string, std::string>& headers,
110 const ErrorHandler& error_handler, auth::AuthSession& session);
111
114 const std::string& path, const std::unordered_map<std::string, std::string>& params,
115 const std::unordered_map<std::string, std::string>& headers,
116 const ErrorHandler& error_handler, auth::AuthSession& session);
117
118 private:
120 Result<std::string> RequestUri(const std::string& path) const;
121
122 std::optional<std::string> base_uri_;
123 std::unordered_map<std::string, std::string> default_headers_;
124 std::chrono::milliseconds connection_timeout_;
125 std::chrono::milliseconds socket_timeout_;
126 std::unique_ptr<cpr::ConnectionPool> connection_pool_;
127};
128
129} // namespace iceberg::rest
Definition expected.h:1199
Error handler interface for processing REST API error responses. Maps HTTP status codes to appropriat...
Definition error_handlers.h:37
HTTP client for making requests to Iceberg REST Catalog API.
Definition http_client.h:73
virtual Result< HttpResponse > Delete(const std::string &path, const std::unordered_map< std::string, std::string > &params, const std::unordered_map< std::string, std::string > &headers, const ErrorHandler &error_handler, auth::AuthSession &session)
Sends a DELETE request.
virtual Result< HttpResponse > Get(const std::string &path, const std::unordered_map< std::string, std::string > &params, const std::unordered_map< std::string, std::string > &headers, const ErrorHandler &error_handler, auth::AuthSession &session)
Sends a GET request.
HttpClient(std::unordered_map< std::string, std::string > default_headers={}, std::chrono::milliseconds connection_timeout={}, std::chrono::milliseconds socket_timeout={}, std::optional< std::string > base_uri=std::nullopt)
virtual Result< HttpResponse > PostForm(const std::string &path, const std::unordered_map< std::string, std::string > &form_data, const std::unordered_map< std::string, std::string > &headers, const ErrorHandler &error_handler, auth::AuthSession &session)
Sends a POST request with form data.
virtual Result< HttpResponse > Post(const std::string &path, const std::string &body, const std::unordered_map< std::string, std::string > &headers, const ErrorHandler &error_handler, auth::AuthSession &session)
Sends a POST request.
virtual Result< HttpResponse > Head(const std::string &path, const std::unordered_map< std::string, std::string > &headers, const ErrorHandler &error_handler, auth::AuthSession &session)
Sends a HEAD request.
A simple wrapper for cpr::Response.
Definition http_client.h:46
std::string body() const
Get the body of the response as a string.
int32_t status_code() const
Get the HTTP status code of the response.
std::unordered_map< std::string, std::string > headers() const
Get the headers of the response as a map.
An authentication session that can authenticate outgoing HTTP requests.
Definition auth_session.h:50
Define symbol visibility macros for the REST catalog library.
REST catalog APIs.
Definition auth_manager.h:34
Define Result, Status, and error helpers.