[OUTDATED] A light HTTP framework for Rust

Overview

Rustful

Join the chat at https://gitter.im/Ogeon/rustful

Build Status Windows Build status

A light HTTP framework for Rust, with REST-like features. The main purpose of Rustful is to create a simple, modular and non-intrusive foundation for HTTP applications. It has a mainly stateless structure, which naturally allows it to run both as one single server and as multiple instances in a cluster.

Some of the features are:

  • Generic response handlers. Just use a function or implement the Handler trait.
  • Some handy macros reduces the risk for typos and makes life easier.
  • Variables in routes, that can capture parts of the requested path.
  • Pluggable request and response filtering.

Online documentation.

Getting Started

Cargo.toml Entries

Add the following lines to your Cargo.toml file:

[dependencies]
rustful = "0.9"

Cargo Features

Some parts of Rustful can be toggled using Cargo features:

  • ssl - Enable SSL, and thereby HTTPS. Enabled by default.
  • multipart - Enable parsing of multipart/form-data requests. Enabled by default.

Using SSL

Rustful support SSL (HTTPS), but does not provide the actual SSL connection. It's however compatible with anything that's made for the same Hyper version, so all you have to do is find the one that suits your needs and plug it into the server:

let server_result = Server {
    handlers: router,
    host: 8080.into(),
    ..Server::default()
}.run_https(my_ssl_server);

Write Your Server

Here is a simple example of what a simple project could look like. Visit http://localhost:8080 or http://localhost:8080/Olivia (if your name is Olivia) to try it.

//Include macros to be able to use `insert_routes!`.
#[macro_use]
extern crate log;
extern crate env_logger;

extern crate rustful;

use std::error::Error;

use rustful::{Server, Context, Response, DefaultRouter};

fn say_hello(context: Context, response: Response) {
    //Get the value of the path variable `:person`, from below.
    let person = match context.variables.get("person") {
        Some(name) => name,
        None => "stranger".into()
    };

    //Use the name from the path variable to say hello.
    response.send(format!("Hello, {}!", person));
}

fn main() {
    env_logger::init().unwrap();

    //Create a DefaultRouter and fill it with handlers.
    let mut router = DefaultRouter::<fn(Context, Response)>::new();
    router.build().many(|mut node| {
        //Handle requests for root...
        node.then().on_get(say_hello);

        //...and one level below.
        //`:person` is a path variable and it will be accessible in the handler.
        node.path(":person").then().on_get(say_hello);
    });

    //Build and run the server.
    let server_result = Server {
        handlers: router,

        //Turn a port number into an IPV4 host address (0.0.0.0:8080 in this case).
        host: 8080.into(),

        //Use default values for everything else.
        ..Server::default()
    }.run();

    match server_result {
        Ok(_server) => {},
        Err(e) => error!("could not start server: {}", e.description())
    }
}

Contributing

Contributions are always welcome, even if it's a small typo fix (or maybe I should say "especially typo fixes"). You can fork the project and open a pull request with your changes, or create an issue if you just want to report or request something. Are you not sure about how to implement your change? Is it still a work in progress? Don't worry. You can still open a pull request where we can discuss it and do it step by step.

New features are as welcome as fixes, so pull requests and proposals with enhancements are very much appreciated, but please explain your feature and give a good motivation to why it should be included. It makes things much easier, both for reviewing the feature and for those who are not as familiar with how things work. You can always open an issue where we can discuss the feature and see if it should be included. Asking is better than assuming!

Testing

Rustful is tested on Linux, using Travis, and on Windows, using AppVeyor and a pull request will not be approved unless it passes these tests. It is therefore a good idea to run tests locally, before pushing your changes, so here is a small list of useful commands:

  • cargo test - Basic unit, documentation and compile tests.
  • cargo build --no-default-features - Check if the most minimal version of Rustful builds.
  • cargo build --no-default-features --features "feature1 feature2" - Check if Rustful with only feature1 and feature2 enabled builds.
  • cargo run --example example_name - check if the example example_name behaves as expected (see the example directory).

Travis and AppVeyor will run the tests with the strict feature enabled. This turns warnings and missing documentation into compile errors, which may be harsh, but it's for the sake of the user. Everything should have a description and it's not nice to see warnings from your dependencies when you are compiling your project, right? It's therefore recommend that you run your own tests with the strict feature enabled before pushing, just to see if you missed something.

Automatic Feature Testing

User facing Cargo features are automatically gathered from Cargo.toml and tested one at the time, using scripts/test_features.sh. The lack of public and private features forces us to use a special annotation to differ between internal and user facing feature. Here is an simple example snippet of how the Cargo.toml is expected to look:

#...

[features]
default = ["feature_a", "feature_b"]
feature_a = ["feature_c"]
feature_b = []

#internal
feature_c = []

[dependencies.optional_lib]
#feature
optional=true

#...

Features that are supposed to be available to the user has to be declared before the #internal comment. This will tell the test script that these are supposed to be tested.

Dependency libraries can also be features, so we have to annotate these as well. Each dependency that is supposed to work as a user facing feature will need a #feature comment somewhere within its declaration. This will only work with features that are declared using the above form, and not the feature_lib = { ... } form.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

You might also like...
Host These Things Please - a basic http server for hosting a folder fast and simply

http Host These Things Please - a basic HTTP server for hosting a folder fast and simply Selected features See the manpage for full list. Symlinks fol

🌟 For when you really just want to serve some files over HTTP right now!
🌟 For when you really just want to serve some files over HTTP right now!

miniserve - a CLI tool to serve files and dirs over HTTP For when you really just want to serve some files over HTTP right now! miniserve is a small,

Add Facebook and Google authentication to your HTTP REST API in Actix-web

I created this project while learning Rust. Project shows how to handle Facebook and Google token verification in Rust using Actix-Web. Hope this help

RUSTENGINE is the high-assurance HTTP server.

RUSTENGINE Table of Contents RUSTENGINE Table of Contents About RUSTENGINE Inspiration with Rust Features Compares with Nginx Build & Run About this R

OxHTTP is a very simple synchronous HTTP client and server

OxHTTP is a very simple synchronous implementation of HTTP 1.1 in Rust. It provides both a client and a server.

A synchronous HTTP server built on hyper.

Astra Astra is a synchronous HTTP server built on top of hyper. use astra::{Body, Response, Server}; fn main() { Server::bind("localhost:3000")

Operator is a web server. You provide a directory and Operator serves it over HTTP.
Operator is a web server. You provide a directory and Operator serves it over HTTP.

Operator Operator is a web server. You provide a directory and Operator serves it over HTTP. It serves static files the way you'd expect, but it can a

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix Web Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust Features Supports HTTP/1.x and HTTP/2 Streaming and pipelining

An Extensible, Concurrent Web Framework for Rust

Iron Extensible, Concurrency Focused Web Development in Rust. Response Timer Example Note: This example works with the current iron code in this repos

:zap: fast http framework for rust

zap âš¡ The mission of zap is, to deliver a basic, but fast rust web server library. Documentation About This code is based on tokio's minihttp project,

Daniel Oltmanns 51 Jun 7, 2022
Fully async-await http server framework

Saphir is a fully async-await http server framework for rust The goal is to give low-level control to your web stack (as hyper does) without the time

Richer Archambault 83 Dec 19, 2022
Node.js http server framework powered by Hyper native binding.

hnsjs POC project. Install this test package yarn add @hnsjs/core Support matrix node10 node12 node14 node15 Windows x64 ✓ ✓ ✓ ✓ Windows x32 ✓ ✓ ✓ ✓

LongYinan 18 Nov 23, 2022
Simple http server in Rust (Windows/Mac/Linux)

How it looks like? Screenshot Command Line Arguments Simple HTTP(s) Server 0.6.1 USAGE: simple-http-server [FLAGS] [OPTIONS] [--] [root] FLAGS:

LinFeng Qian 788 Dec 28, 2022
An HTTP library for Rust

hyper A fast and correct HTTP implementation for Rust. HTTP/1 and HTTP/2 Asynchronous design Leading in performance Tested and correct Extensive produ

null 11k Jan 7, 2023
Low level HTTP server library in Rust

tiny-http Documentation Tiny but strong HTTP server in Rust. Its main objectives are to be 100% compliant with the HTTP standard and to provide an eas

null 785 Dec 29, 2022
Akasio is a simple HTTP server that redirects traffic based on a JSON redirect table. This is its Rust implementation.

This page is inaccurate and is pending updates. Akasio (Rust) Description Akasio is a simple HTTP server that redirects traffic based on a JSON redire

K4YT3X 5 May 2, 2022
service_policy_kit is a Rust based toolkit for verifying HTTP services against policies.

Service Policy Kit service_policy_kit is a Rust based toolkit for verifying HTTP services against policies. You can: Build a complete testing framewor

null 19 Dec 5, 2022
Completely OBSOLETE Rust HTTP library (server and client)

OBSOLETION NOTICE This library is DEAD. It was a useful experiment and is now being replaced under the scope of the Teepee (experimentation grounds at

Chris Morgan 390 Dec 1, 2022
Archibald is my attempt at learning Rust and writing a HTTP 1.1 web server.

Archibald To be a butler, is to be able to maintain an even-temper, at all times. One must have exceptional personal hygiene and look sharp and profes

Daniel Cuthbert 4 Jun 20, 2022