Expand description
§Lob (Rust)
A small, async Rust client for the Lob API, built on top of reqwest with a type-safe builder API.
This library is intentionally minimal and focuses on:
- Explicit client construction
- A fluent postcard request builder
- Strongly typed error handling
§Sending A Postcard
ⓘ
use lob::LobClient;
use serde::Serialize;
let client = reqwest::Client::new();
let lob_client = LobClient::builder()
.client(client)
.api_key("MY_API_KEY")
.build();
const CASE_NUMBER: &str = "JP01-25-E01";
const FRONT_HTML: &str = r#"
<html>
<head>
<style>
p {
padding: 20px;
}
</style>
</head>
<body>
<p>Hello {{case_number}}!</p>
</body>
</html>
"#;
const BACK_HTML: &str = r#"
<html>
<head>
<style>
p {
padding: 20px;
}
</style>
</head>
<body>
<p>Back Side: {{case_number}}!</p>
</body>
</html>
"#;
#[derive(Serialize)]
struct MergeVar {
case_number: &'static str,
}
let response = lob_client
.create_postcard()
.idempotency_key(CASE_NUMBER)
.name("Spanish Consulate")
.address_line_1("1800 Bering Dr")
.address_line_2("750")
.city("Houston")
.state("TX")
.zip_code("77057")
.front(FRONT_HTML)
.back(BACK_HTML)
.use_type(UseType::Marketing)
.size(Size::FourBySix)
.mail_type(MailType::UspsFirstClass)
.description("Postcard To Spanish Consulate")
.merge(MergeVar {
case_number: CASE_NUMBER,
})
.send()
.await
.unwrap();
println!("{response:#?}");Structs§
- ApiError
- An Api Error Message From Lob
- Create
Postcard Response - The response from lob’s api for creating a postcard
- LobClient
- A reusable client for interacting with the Lob API.
Enums§
- Create
Postcard Error - Errors that can occur while performing a Lob “create postcard” request.
- Mail
Type - An enum designating the mail postage type
- Size
- Specifies the size of the postcard. Only 4x6 postcards can be sent to international destinations.
- UseType
- Identifying your mail use type helps Lob populate the right mail settings and postage options to ensure your mail is produced and delivered in an optimal way. Lob requires that you identify—or tag—your mail with one of the following use type options: