3 releases

0.3.2 Mar 18, 2024
0.3.1 Mar 15, 2024
0.3.0 Mar 15, 2024

#1172 in HTTP server

Download history 2/week @ 2024-07-06 5/week @ 2024-09-14 31/week @ 2024-09-21 46/week @ 2024-09-28 3/week @ 2024-10-05

85 downloads per month

MIT license

680KB
685 lines

Surfer Logo

Surfer

A lightweight, asynchronous backend framework for Rust with Rust

It's a simple, lightweight and asynchronous backend framework for Rust. It's built on top of async-std and provides easy route registration and handling of HTTP requests. It also provides built-in response structs for response creation and JSON response support for structs with Serialize and Deserialize implemented.

🚀 Features

  • Asynchronous handling of HTTP requests (using async-std)
  • Easy route registration with the route! macro
  • Built-in response structs for easy response creation
  • JSON response support for structs with Serialize and Deserialize implemented
  • Use the #[surfer_launch] macro to start the server to not have to write #[async_std::main] (internally it's the same thing :D)

📦 Installation

Clone the repository and add the following to your Cargo.toml:

[dependencies]
surfer = "0.3.2"

📚 Example Usage

extern crate surfer;

use serde_json::json;
use surfer::request::Method::GET;
use surfer::request::Request;
use surfer::response::json_response::JsonResponse;
use surfer::response::{IntoResponse, Response};
use surfer::route;
use surfer::server::Server;
use surfer_macros::surfer_launch;

async fn index(_: Request) -> Response {
    let json_obj = json!({
        "message": "Hello, Surfer!"
    });
    JsonResponse {
        status_code: 200,
        headers: None,
        body: json_obj,
    }
    .into_response()
    .await
}

#[surfer_launch]
async fn main() {
    let mut server = Server::new(None, None);
    server.register_route(route!(GET, "/", index));
    server.listen().await;
}

📖 Documentation

For more detailed documentation, get known to the source code 🫠

Dependencies

~10–20MB
~301K SLoC