iceberg-cpp
Loading...
Searching...
No Matches
endpoint.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 <string>
23#include <string_view>
24
25#include "iceberg/catalog/rest/iceberg_rest_export.h"
26#include "iceberg/result.h"
27
30
31namespace iceberg::rest {
32
34enum class HttpMethod : uint8_t { kGet, kPost, kPut, kDelete, kHead };
35
37constexpr std::string_view ToString(HttpMethod method);
38
43class ICEBERG_REST_EXPORT Endpoint {
44 public:
50 static Result<Endpoint> Make(HttpMethod method, std::string_view path);
51
57 static Result<Endpoint> FromString(std::string_view str);
58
60 constexpr HttpMethod method() const { return method_; }
61
63 std::string_view path() const { return path_; }
64
66 std::string ToString() const;
67
68 constexpr bool operator==(const Endpoint& other) const {
69 return method_ == other.method_ && path_ == other.path_;
70 }
71
72 // Namespace endpoints
73 static Endpoint ListNamespaces() {
74 return {HttpMethod::kGet, "/v1/{prefix}/namespaces"};
75 }
76 static Endpoint GetNamespaceProperties() {
77 return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}"};
78 }
79 static Endpoint NamespaceExists() {
80 return {HttpMethod::kHead, "/v1/{prefix}/namespaces/{namespace}"};
81 }
82 static Endpoint CreateNamespace() {
83 return {HttpMethod::kPost, "/v1/{prefix}/namespaces"};
84 }
85 static Endpoint UpdateNamespace() {
86 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/properties"};
87 }
88 static Endpoint DropNamespace() {
89 return {HttpMethod::kDelete, "/v1/{prefix}/namespaces/{namespace}"};
90 }
91
92 // Table endpoints
93 static Endpoint ListTables() {
94 return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}/tables"};
95 }
96 static Endpoint LoadTable() {
97 return {HttpMethod::kGet, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"};
98 }
99 static Endpoint TableExists() {
100 return {HttpMethod::kHead, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"};
101 }
102 static Endpoint CreateTable() {
103 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/tables"};
104 }
105 static Endpoint UpdateTable() {
106 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"};
107 }
108 static Endpoint DeleteTable() {
109 return {HttpMethod::kDelete, "/v1/{prefix}/namespaces/{namespace}/tables/{table}"};
110 }
111 static Endpoint RenameTable() {
112 return {HttpMethod::kPost, "/v1/{prefix}/tables/rename"};
113 }
114 static Endpoint RegisterTable() {
115 return {HttpMethod::kPost, "/v1/{prefix}/namespaces/{namespace}/register"};
116 }
117 static Endpoint ReportMetrics() {
118 return {HttpMethod::kPost,
119 "/v1/{prefix}/namespaces/{namespace}/tables/{table}/metrics"};
120 }
121 static Endpoint TableCredentials() {
122 return {HttpMethod::kGet,
123 "/v1/{prefix}/namespaces/{namespace}/tables/{table}/credentials"};
124 }
125
126 // Transaction endpoints
127 static Endpoint CommitTransaction() {
128 return {HttpMethod::kPost, "/v1/{prefix}/transactions/commit"};
129 }
130
131 private:
132 Endpoint(HttpMethod method, std::string_view path) : method_(method), path_(path) {}
133
134 HttpMethod method_;
135 std::string path_;
136};
137
138} // namespace iceberg::rest
139
140// Specialize std::hash for Endpoint
141namespace std {
142template <>
143struct hash<iceberg::rest::Endpoint> {
144 std::size_t operator()(const iceberg::rest::Endpoint& endpoint) const noexcept {
145 std::size_t h1 = std::hash<int32_t>{}(static_cast<int32_t>(endpoint.method()));
146 std::size_t h2 = std::hash<std::string_view>{}(endpoint.path());
147 return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
148 }
149};
150} // namespace std
An Endpoint is an immutable value object identifying a specific REST API operation....
Definition endpoint.h:43
constexpr HttpMethod method() const
Get the HTTP method.
Definition endpoint.h:60
std::string_view path() const
Get the path template.
Definition endpoint.h:63
HttpMethod
HTTP method enumeration.
Definition endpoint.h:34
STL namespace.