Crate http_api

Crate http_api 

Source
Expand description

A Rust crate for declaring typed HTTP APIs using procedural macros.

This crate provides declarative macros for defining type-safe HTTP communication patterns:

  • xhr_api! - Request/response endpoints with guaranteed acknowledgment
  • sse_api! - Server-Sent Events for server-to-client streaming
  • websocket_api! - Bidirectional WebSocket messaging with fire-and-forget semantics

§XHR API Example

use http_api::xhr_api;

xhr_api! {
    pub mod todo_api {
        get_todos -> {
            todos: Vec<String>
        };

        add_todo {
            title: String
        } -> {
            id: u64
        };
    }
}

§SSE API Example

use http_api::sse_api;

sse_api! {
    pub mod notifications {
        #[derive(Debug, Clone)]
        notification_event {
            message: String,
            priority: u8,
        };

        #[derive(Debug, Clone)]
        heartbeat;
    }
}

§WebSocket API Example

use http_api::websocket_api;

websocket_api! {
    pub mod chat_ws {
        client_to_server {
            #[derive(Debug, Clone)]
            send_message {
                content: String,
                room_id: u64,
            };

            #[derive(Debug, Clone)]
            ping;
        }

        server_to_client {
            #[derive(Debug, Clone)]
            message_received {
                from_user: String,
                content: String,
            };

            #[derive(Debug, Clone)]
            pong;
        }
    }
}

Modules§

adapters
HTTP framework adapters for server and client implementations.

Macros§

sse_api
websocket_api
xhr_api

Traits§

HttpClient
Trait for HTTP client implementations.
HttpHandler
Trait for handling HTTP requests on the server side.
HttpServer
Marker trait for HTTP server implementations.