pub struct Api<B: Backend> {
pub backend: B,
pub description: String,
pub id: String,
pub root: Url,
}
Expand description
A STAC server API.
Fields§
§backend: B
The backend storage for this API.
description: String
The text description of this API.
id: String
The catalog id of this API.
root: Url
The root url of this API.
Implementations§
Source§impl<B: Backend> Api<B>
impl<B: Backend> Api<B>
Sourcepub fn new(backend: B, root: &str) -> Result<Api<B>>
pub fn new(backend: B, root: &str) -> Result<Api<B>>
Creates a new API with the given backend.
§Examples
use stac_server::{Api, MemoryBackend};
let backend = MemoryBackend::new();
let api = Api::new(backend, "http://stac.test").unwrap();
Sourcepub fn id(self, id: impl ToString) -> Api<B>
pub fn id(self, id: impl ToString) -> Api<B>
Sets this API’s id.
§Examples
use stac_server::{Api, MemoryBackend};
let backend = MemoryBackend::new();
let api = Api::new(backend, "http://stac.test").unwrap().id("an-id");
Sourcepub fn description(self, description: impl ToString) -> Api<B>
pub fn description(self, description: impl ToString) -> Api<B>
Sets this API’s description.
§Examples
use stac_server::{Api, MemoryBackend};
let backend = MemoryBackend::new();
let api = Api::new(backend, "http://stac.test").unwrap().description("a description");
Sourcepub async fn root(&self) -> Result<Root>
pub async fn root(&self) -> Result<Root>
Returns the root of the API.
§Examples
use stac_server::{Api, MemoryBackend};
let api = Api::new(MemoryBackend::new(), "http://stac.test").unwrap();
let root = api.root().await.unwrap();
Sourcepub fn conformance(&self) -> Conformance
pub fn conformance(&self) -> Conformance
Returns the conformance classes.
§Examples
use stac_server::{Api, MemoryBackend};
let api = Api::new(MemoryBackend::new(), "http://stac.test").unwrap();
let conformance = api.conformance();
Sourcepub fn queryables(&self) -> Value
pub fn queryables(&self) -> Value
Returns queryables.
Sourcepub async fn collections(&self) -> Result<Collections>
pub async fn collections(&self) -> Result<Collections>
Returns the collections from the backend.
§Examples
use stac_server::{Api, MemoryBackend};
let api = Api::new(MemoryBackend::new(), "http://stac.test").unwrap();
let collections = api.collections().await.unwrap();
Sourcepub async fn collection(&self, id: &str) -> Result<Option<Collection>>
pub async fn collection(&self, id: &str) -> Result<Option<Collection>>
Returns the collections from the backend.
§Examples
use stac_server::{Api, MemoryBackend, Backend};
use stac::Collection;
let mut backend = MemoryBackend::new();
backend.add_collection(Collection::new("an-id", "a description")).await.unwrap();
let api = Api::new(backend, "http://stac.test").unwrap();
let collection = api.collection("an-id").await.unwrap().unwrap();
Sourcepub async fn items(
&self,
collection_id: &str,
items: Items,
) -> Result<Option<ItemCollection>>
pub async fn items( &self, collection_id: &str, items: Items, ) -> Result<Option<ItemCollection>>
Returns all items for a given collection.
§Examples
use stac_server::{Api, MemoryBackend, Backend};
use stac::{Collection, Item};
use stac_api::Items;
let mut backend = MemoryBackend::new();
backend.add_collection(Collection::new("collection-id", "a description")).await.unwrap();
backend.add_item(Item::new("item-id").collection("collection-id")).await.unwrap();
let api = Api::new(backend, "http://stac.test").unwrap();
let items = api.items("collection-id", Items::default()).await.unwrap().unwrap();
assert_eq!(items.items.len(), 1);
Sourcepub async fn item(
&self,
collection_id: &str,
item_id: &str,
) -> Result<Option<Item>>
pub async fn item( &self, collection_id: &str, item_id: &str, ) -> Result<Option<Item>>
Returns an item.
§Examples
use stac_server::{Api, MemoryBackend, Backend};
use stac::{Collection, Item};
use stac_api::Items;
let mut backend = MemoryBackend::new();
backend.add_collection(Collection::new("collection-id", "a description")).await.unwrap();
backend.add_item(Item::new("item-id").collection("collection-id")).await.unwrap();
let api = Api::new(backend, "http://stac.test").unwrap();
let item = api.item("collection-id", "item-id").await.unwrap().unwrap();
Sourcepub async fn search(
&self,
search: Search,
method: Method,
) -> Result<ItemCollection>
pub async fn search( &self, search: Search, method: Method, ) -> Result<ItemCollection>
Searches the API.
§Examples
use stac_api::Search;
use stac_server::{Api, MemoryBackend, Backend};
use http::Method;
let api = Api::new(MemoryBackend::new(), "http://stac.test").unwrap();
let item_collection = api.search(Search::default(), Method::GET).await.unwrap();
Trait Implementations§
Auto Trait Implementations§
impl<B> Freeze for Api<B>where
B: Freeze,
impl<B> RefUnwindSafe for Api<B>where
B: RefUnwindSafe,
impl<B> Send for Api<B>
impl<B> Sync for Api<B>
impl<B> Unpin for Api<B>where
B: Unpin,
impl<B> UnwindSafe for Api<B>where
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more