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 (Async)

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 core::Body;
pub use core::Header;
pub use core::Path;
pub use core::Query;
pub use core::RequestBuilder;
pub use core::Result;
pub use core::RetrofitError;
pub use async_client::Chain;
pub use async_client::Interceptor;
pub use async_client::Request;
pub use async_client::Response;
pub use async_client::Retrofit;
pub use async_client::RetrofitBuilder;

Modules§

async_client
Async HTTP client implementation
core
Core module containing shared types and utilities

Attribute Macros§

api
#[api(base_url)] or #[api(base_url, blocking)] 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