Expand description

CI crates.io docs.rs

A simple http server library.

Example

use fire::{data_struct, get};

// To access data from request handlers
data_struct! {
	#[derive(Debug)]
	struct Data {
		global_name: String
	}
}

// handle a simple get request
get! {
	Root, "/",
	|_r, global_name| -> String {
		format!("Hi, this is {}", global_name)
	}
}

#[tokio::main]
async fn main() {
	let data = Data {
		global_name: "fire".into()
	};

	let mut server = fire::build("0.0.0.0:3000", data)
		.expect("Failed to parse address");

	server.add_route(Root);

	server.light().await
		.expect("server paniced");
}

For more examples look in the examples directory and the test directory.

Features

  • json
  • fs
  • encdec (adds percent encoding and decoding to header values)
  • http2 (enables http 2 support)
  • ws (adds websocket support)

Re-exports

pub use error::Result;
pub use error::Error;
pub use http;

Modules

Macros

To access data from request handlers you need to create a data struct every request receivers a reference to this struct.

Static delete handler.

Dynamic delete request handler.

Dynamic get request handler.

Dynamic head request handler.

Dynamic post request handler.

Dynamic put request handler.

Dynamic Route

Dynamic get request handler which servers a file if a path is provided.

Static get handler.

Static get handler which servers/returns a file.

Static head handler.

needs to return crate::Result

Static post handler.

Static put handler.

Basic Route

Static get handler which servers files from a directory.

Static Route

Creates a WebSocket route

Structs

FireBuilder gathers all materials needed to light a fire (start a server).

Traits

A trait that simplifies the bounds on other methods or structs.

Functions

Prepares a server.