Expand description
§Objectstore Client
The client is used to interface with the Objectstore backend. It handles responsibilities like transparent compression, and making sure that uploads and downloads are done as efficiently as possible.
§Usage
Here’s a basic example that shows how to use this client:
use objectstore_client::{Client, Usecase, Result};
async fn example_basic() -> Result<()> {
let client = Client::new("http://localhost:8888/")?;
let session = Usecase::new("attachments")
.for_project(42, 1337)
.session(&client)?;
let response = session.put("Hello, world!")
.send()
.await
.expect("put to succeed");
let object = session
.get(&response.key)
.send()
.await?
.expect("object to exist");
assert_eq!(object.payload().await?, "hello world");
session
.delete(&response.key)
.send()
.await
.expect("delete to succeed");
Ok(())
}In practice, you would most likely want to store the Client and Usecase
in something like a static and reuse them, like so:
use std::time::Duration;
use std::sync::LazyLock;
use objectstore_client::{Client, Compression, Usecase, Result};
static OBJECTSTORE_CLIENT: LazyLock<Client> = LazyLock::new(|| {
Client::builder("http://localhost:8888/")
// Optionally, propagate tracing headers to use distributed tracing in Sentry
.propagate_traces(true)
// Customize the `reqwest::ClientBuilder`
.configure_reqwest(|builder| {
builder.pool_idle_timeout(Duration::from_secs(90))
.pool_max_idle_per_host(10)
})
.build()
.expect("Objectstore client to build successfully")
});
static ATTACHMENTS: LazyLock<Usecase> = LazyLock::new(|| {
Usecase::new("attachments")
});
async fn example() -> Result<()> {
let session = OBJECTSTORE_CLIENT
.session(ATTACHMENTS.for_project(42, 1337))?;
let response = session.put("Hello, world!").send().await?;
let object = session
.get(&response.key)
.send()
.await?
.expect("object to exist");
assert_eq!(object.payload().await?, "hello world");
session
.delete(&response.key)
.send()
.await
.expect("deletion to succeed");
Ok(())
}See the API docs for more in-depth documentation.
§License
Like Sentry, Objectstore is licensed under the FSL. See the LICENSE.md file
and this blog post
for more information.
Modules§
- utils
- Utility functions that might be useful when working with Objectstore.
Structs§
- Client
- A client for Objectstore. Use
Client::builderto configure and construct a Client. - Client
Builder - Builder to create a
Client. - Delete
Builder - A
deleterequest builder. - GetBuilder
- A
getrequest builder. - GetResponse
- The result from a successful
get()call. - PutBuilder
- A
putrequest builder. - PutResponse
- The response returned from the service after uploading an object.
- Scope
- A
Scopeis a sequence of key-value pairs that defines a (possibly nested) namespace within aUsecase. - Session
- Represents a session with Objectstore, tied to a specific Usecase and Scope within it.
- Usecase
- An identifier for a workload in Objectstore, along with defaults to use for all operations within that Usecase.
Enums§
- Compression
- The compression algorithm of an object to upload.
- Error
- Errors that can happen within the objectstore-client
- Expiration
Policy - The per-object expiration policy
Type Aliases§
- Client
Stream - The type of
Streamto be used for a PUT request. - Delete
Response - The result from a successful
delete()call. - Result
- A convenience alias that defaults our
Errortype.