Skip to content
yansongdaPublic

About

๐Ÿงฐ Artisan โ€” a growing collection of handy Rust crates. Ships artisan-http: an HTTP client with onion-model middleware & a plugin system (the Rust sibling of yansongda/artful).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

75 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

English | ็ฎ€ไฝ“ไธญๆ–‡

Artisan

Workspace Structure

artisan/
โ”œโ”€โ”€ Cargo.toml              # Workspace configuration
โ”œโ”€โ”€ src/lib.rs              # Facade (feature-controlled re-exports)
โ””โ”€โ”€ artisan-http/           # HTTP implementation
    โ”œโ”€โ”€ src/                # Core implementation
    โ”œโ”€โ”€ tests/              # Tests
    โ”œโ”€โ”€ examples/           # Examples
    โ””โ”€โ”€ docs/               # Architecture docs

Crates

Crate Role Docs
artisan Facade with feature-controlled re-exports docs.rs/artisan
artisan-http HTTP client, onion model, plugin system README

Installation

# Recommended: via the facade (HTTP included by default)
cargo add artisan

# Depend on the implementation crate directly
cargo add artisan-http

# Pure facade (HTTP disabled)
cargo add artisan --no-default-features
# Cargo.toml
[dependencies]
artisan = "0.18.0"

# Depend on the implementation crate directly
[dependencies]
artisan-http = "0.18.0"

# Pure facade (HTTP disabled)
[dependencies]
artisan = { version = "0.18.0", default-features = false }

Quick Start

artisan-http

Events (artisan-http)

Each Artful instance carries a built-in event dispatcher: register listeners via the builder to observe the request lifecycle without writing a full plugin (zero cost when no listener is registered).

use artisan_http::{Artful, Event, EventListener};
use std::sync::Arc;

struct LoggingListener;

impl EventListener for LoggingListener {
    fn name(&self) -> &'static str {
        "LoggingListener"
    }

    fn on_event(&self, event: &mut Event<'_>) -> artisan_http::Result<()> {
        match event {
            Event::ArtfulStart { params, plugins } => {
                eprintln!("ArtfulStart: {} params, {} plugins", params.len(), plugins.len())
            }
            Event::HttpStart { rocket } => {
                eprintln!("HttpStart: {} {}", rocket.config.method, rocket.config.url)
            }
            Event::HttpEnd { rocket } => {
                eprintln!("HttpEnd: {:?}", rocket.destination_origin.as_ref().map(|r| r.status()))
            }
            Event::HttpError { error, .. } => eprintln!("HttpError: {error}"),
            Event::ArtfulEnd { .. } => eprintln!("ArtfulEnd"),
        }
        Ok(()) // bypass listener: consume errors internally, never return Err
    }
}

let artful = Artful::builder()
    .event_listener(Arc::new(LoggingListener))
    .build()?;
Event Fires Mutability
ArtfulStart before the plugin chain starts read-only
HttpStart before the HTTP request is sent, at the tail core action execution point (IgniteCore, mounted automatically by the framework; radar already built in a normal chain; None if the chain lacks AddRadarPlugin - the event still fires; mutate the request via the *_mut accessors on rocket.radar) mutable
HttpEnd after a successful response, before parsing (response body is NOT readable - body consumption belongs to direction parsing; only status / headers are readable) read-only
HttpError when the HTTP request execution fails (the error still propagates) read-only
ArtfulEnd after the chain succeeds, before returning the destination (may rewrite rocket.destination) mutable
  • Listeners are synchronous and must be non-blocking โ€” spawn heavy work yourself (tokio::spawn).
  • A listener returning Err aborts the main flow (propagates as EventListenerError). Bypass listeners should consume errors internally and always return Ok(()).
  • HttpEnd cannot read the response body (ownership belongs to direction parsing); only status / headers are available there.

See the artisan-http README Events section for details, or try cargo run -p artisan-http --example event.

Examples

artisan-http

cargo run -p artisan-http --example basic
cargo run -p artisan-http --example config
cargo run -p artisan-http --example shortcut
cargo run -p artisan-http --example custom_plugin
cargo run -p artisan-http --example direction

License

MIT License

About

๐Ÿงฐ Artisan โ€” a growing collection of handy Rust crates. Ships artisan-http: an HTTP client with onion-model middleware & a plugin system (the Rust sibling of yansongda/artful).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages