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 <cstdint>
23#include <memory>
24#include <string>
25#include <unordered_map>
26
27#include "iceberg/catalog/rest/iceberg_rest_export.h"
29#include "iceberg/result.h"
30
33
34namespace cpr {
35class ConnectionPool;
36} // namespace cpr
37
38namespace iceberg::rest {
39
45class ICEBERG_REST_EXPORT HttpResponse {
46 public:
49
50 HttpResponse(const HttpResponse&) = delete;
51 HttpResponse& operator=(const HttpResponse&) = delete;
52 HttpResponse(HttpResponse&&) noexcept;
53 HttpResponse& operator=(HttpResponse&&) noexcept;
54
56 int32_t status_code() const;
57
59 std::string body() const;
60
62 std::unordered_map<std::string, std::string> headers() const;
63
64 private:
65 friend class HttpClient;
66 class Impl;
67 std::unique_ptr<Impl> impl_;
68};
69
71class ICEBERG_REST_EXPORT HttpClient {
72 public:
73 explicit HttpClient(std::unordered_map<std::string, std::string> default_headers = {});
75
76 HttpClient(const HttpClient&) = delete;
77 HttpClient& operator=(const HttpClient&) = delete;
78 HttpClient(HttpClient&&) = delete;
79 HttpClient& operator=(HttpClient&&) = delete;
80
82 Result<HttpResponse> Get(const std::string& path,
83 const std::unordered_map<std::string, std::string>& params,
84 const std::unordered_map<std::string, std::string>& headers,
85 const ErrorHandler& error_handler, auth::AuthSession& session);
86
88 Result<HttpResponse> Post(const std::string& path, const std::string& body,
89 const std::unordered_map<std::string, std::string>& headers,
90 const ErrorHandler& error_handler,
91 auth::AuthSession& session);
92
94 Result<HttpResponse> PostForm(
95 const std::string& path,
96 const std::unordered_map<std::string, std::string>& form_data,
97 const std::unordered_map<std::string, std::string>& headers,
98 const ErrorHandler& error_handler, auth::AuthSession& session);
99
101 Result<HttpResponse> Head(const std::string& path,
102 const std::unordered_map<std::string, std::string>& headers,
103 const ErrorHandler& error_handler,
104 auth::AuthSession& session);
105
107 Result<HttpResponse> Delete(const std::string& path,
108 const std::unordered_map<std::string, std::string>& params,
109 const std::unordered_map<std::string, std::string>& headers,
110 const ErrorHandler& error_handler,
111 auth::AuthSession& session);
112
113 private:
114 std::unordered_map<std::string, std::string> default_headers_;
115 std::unique_ptr<cpr::ConnectionPool> connection_pool_;
116};
117
118} // namespace iceberg::rest
Error handler interface for processing REST API error responses. Maps HTTP status codes to appropriat...
Definition error_handlers.h:35
HTTP client for making requests to Iceberg REST Catalog API.
Definition http_client.h:71
Definition http_client.cc:36
A simple wrapper for cpr::Response.
Definition http_client.h:45
An authentication session that can authenticate outgoing HTTP requests.
Definition auth_session.h:36