summaryrefslogtreecommitdiff
path: root/cli/tools/registry/api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools/registry/api.rs')
-rw-r--r--cli/tools/registry/api.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/cli/tools/registry/api.rs b/cli/tools/registry/api.rs
index b174ea367..2c08ef52d 100644
--- a/cli/tools/registry/api.rs
+++ b/cli/tools/registry/api.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_runtime::deno_fetch::reqwest;
use serde::de::DeserializeOwned;
@@ -108,3 +109,32 @@ pub async fn parse_response<T: DeserializeOwned>(
x_deno_ray,
})
}
+
+pub async fn get_scope(
+ client: &reqwest::Client,
+ registry_api_url: &str,
+ scope: &str,
+) -> Result<reqwest::Response, AnyError> {
+ let scope_url = format!("{}scope/{}", registry_api_url, scope);
+ let response = client.get(&scope_url).send().await?;
+ Ok(response)
+}
+
+pub fn get_package_api_url(
+ registry_api_url: &str,
+ scope: &str,
+ package: &str,
+) -> String {
+ format!("{}scope/{}packages/{}", registry_api_url, scope, package)
+}
+
+pub async fn get_package(
+ client: &reqwest::Client,
+ registry_api_url: &str,
+ scope: &str,
+ package: &str,
+) -> Result<reqwest::Response, AnyError> {
+ let package_url = get_package_api_url(registry_api_url, scope, package);
+ let response = client.get(&package_url).send().await?;
+ Ok(response)
+}