Crate retrofit_rs

Crate retrofit_rs 

Source
Expand description

§Retrofit-rs

A type-safe, declarative HTTP client library for Rust, inspired by Java Retrofit.

§Features

  • 🎯 Declarative API with procedural macros
  • 🔒 Type-safe at compile time
  • ⚡ Async/await support
  • 🔄 Powerful interceptor system
  • 📝 Automatic serialization/deserialization

§Quick Start

use retrofit_rs::{api, get, Result};
use serde::Deserialize;

#[derive(Deserialize)]
struct User {
    name: String,
}

#[api("https://api.example.com")]
trait MyApi {
    #[get("/users/{id}")]
    async fn get_user(&self, id: u64) -> Result<User>;
}

#[tokio::main]
async fn main() -> Result<()> {
    let api = MyApiClient::new()?;
    let user = api.get_user(1).await?;
    println!("{}", user.name);
    Ok(())
}

Re-exports§

pub use interceptor::Chain;
pub use interceptor::Interceptor;
pub use interceptor::Request;
pub use interceptor::Response;
pub use types::Body;
pub use types::Header;
pub use types::Path;
pub use types::Query;

Modules§

interceptor
interceptors
types
Type wrappers for parameter identification

Structs§

RequestBuilder
HTTP request builder
Retrofit
Retrofit HTTP client
RetrofitBuilder
Retrofit builder

Enums§

RetrofitError
Retrofit error types with detailed context

Type Aliases§

Result
Result type alias for Retrofit operations

Attribute Macros§

api
#[api(base_url)] macro for defining API traits
async_trait
delete
HTTP method attribute macro: DELETE
get
HTTP method attribute macro: GET
patch
HTTP method attribute macro: PATCH
post
HTTP method attribute macro: POST
put
HTTP method attribute macro: PUT