Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make some REST methods public #922

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/catalog/rest/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ impl RestCatalogConfig {
self.url_prefixed(&["tables", "rename"])
}

fn table_endpoint(&self, table: &TableIdent) -> String {
/// Builds a prefixed table endpoint from the given table identifier.
///
/// Outputs an endpoint in the form of `/{base_url}/namespaces/{namespace}/tables/{table}`.
/// The base URL is defined by the catalog config, built from the URI, version and any specified prefix.
pub fn table_endpoint(&self, table: &TableIdent) -> String {
self.url_prefixed(&[
"namespaces",
&table.namespace.to_url_string(),
Expand Down
18 changes: 17 additions & 1 deletion crates/catalog/rest/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use serde::de::DeserializeOwned;
use crate::types::{ErrorResponse, TokenResponse, OK};
use crate::RestCatalogConfig;

pub(crate) struct HttpClient {
/// The HTTP client for the REST catalog
pub struct HttpClient {
client: Client,

/// The token to be used for authentication.
Expand Down Expand Up @@ -216,11 +217,19 @@ impl HttpClient {
Ok(())
}

/// Create a new request builder, from the inner client.
#[inline]
pub fn request<U: IntoUrl>(&self, method: Method, url: U) -> RequestBuilder {
self.client.request(method, url)
}

/// Send a request and parse the response into ``R`` on success, or ``E`` on error.
/// Assert the response code is ``SUCCESS_CODE``, otherwise return an error.
///
/// # Errors
///
/// - If the response code is not ``SUCCESS_CODE``, return an error.
/// - If the response body cannot be parsed into ``R`` or ``E``, return an error.
pub async fn query<
R: DeserializeOwned,
E: DeserializeOwned + Into<Error>,
Expand Down Expand Up @@ -272,6 +281,13 @@ impl HttpClient {
}
}

/// Send a request, dropping any response body on success, parsing the response into ``E`` on error.
/// Assert the response code is ``SUCCESS_CODE``, otherwise return an error.
///
/// # Errors
///
/// - If the response code is not ``SUCCESS_CODE``, return an error.
/// - If the response body cannot be parsed into ``E``, return an error.
pub async fn execute<E: DeserializeOwned + Into<Error>, const SUCCESS_CODE: u16>(
&self,
mut request: Request,
Expand Down
2 changes: 2 additions & 0 deletions crates/catalog/rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ mod client;
mod types;

pub use catalog::*;
pub use client::HttpClient;
pub use types::{ErrorResponse, OK};
6 changes: 4 additions & 2 deletions crates/catalog/rest/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use iceberg::{
};
use serde_derive::{Deserialize, Serialize};

pub(super) const OK: u16 = 200u16;
/// HTTP status code for OK.
pub const OK: u16 = 200u16;
pub(super) const NO_CONTENT: u16 = 204u16;

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -32,8 +33,9 @@ pub(super) struct CatalogConfig {
pub(super) defaults: HashMap<String, String>,
}

/// Response for request errors.
#[derive(Debug, Serialize, Deserialize)]
pub(super) struct ErrorResponse {
pub struct ErrorResponse {
error: ErrorModel,
}

Expand Down
Loading