An expressjs inspired web framework for Rust

Overview

nickel.rs Build Status license Join the chat at https://gitter.im/nickel-org/nickel.rs

nickel.rs is a simple and lightweight foundation for web applications written in Rust. Its API is inspired by the popular express framework for JavaScript.

Hello world

#[macro_use] extern crate nickel;

use nickel::{Nickel, HttpRouter};

fn main() {
    let mut server = Nickel::new();
    server.get("**", middleware!("Hello World"));
    server.listen("127.0.0.1:6767");
}

Dependencies

You'll need to create a Cargo.toml that looks like this;

[package]

name = "my-nickel-app"
version = "0.0.1"
authors = ["yourname"]

[dependencies.nickel]
version = "*"
# If you are using the 'nightly' rust channel you can uncomment
# the line below to activate unstable features
# features = ["unstable"]

# Some examples require the `rustc_serialize` crate, which will
# require uncommenting the lines below
# [dependencies]
# rustc-serialize = "*"

You can then compile this using Cargo build and run it using Cargo run. After it's running you should visit http://localhost:6767 to see your hello world!

More examples

More examples can be found in the examples directory and the full documentation can be found here.

Contributing

nickel.rs is a community effort. We welcome new contributors with open arms. Please read the contributing guide here first.

If you're looking for inspiration, there's list of open issues right here on github.

If you need a helping hand reach out to @jolhoeft, @cburgdorf, @Ryman or @SimonPersson.

And hey, did you know you can also contribute by just starring the project here on github :)

Development Plan

Version Branch Description
0.11.x maint-0.11.x hyper-0.10.x (synchronous version), bug fixes only
0.12.x master hyper-0.14.x (asynchronous version)
0.13.x new features, possibly will be 1.0 instead
Comments
  • Add Mount middleware

    Add Mount middleware

    Attempt at #259.

    This middleware takes a mount point and a Middleware. When invoked, the mount point is compared with the incoming request, and if they match the underlying middleware is invoked but with the request path rewritten to have the mount point as root.

    Ping @cburgdorf

    opened by SimonPersson 28
  • feat(nickel): add options to Nickel, allowing the user to disable the messages output on listen

    feat(nickel): add options to Nickel, allowing the user to disable the messages output on listen

    This is in relation to the pull request #124 - it adds two methods to Nickel - a static default_options, and set_options. The only option available is output_on_listen, which when disabled, won't display "Listening on x.x.x.x:xxxx/Press Ctrl+C to shutdown the server" (it is enabled by default, which is the current behavior). This could be extended later on for whatever other options.

    opened by ixjf 27
  • Add some testing infrastructure for feature testing examples

    Add some testing infrastructure for feature testing examples

    I'd like to make an attempt soon to refactor some of the internals so that we can actually do decent unit-testing, and to remove some gotchas. To do so with any confidence we need to have some end-to-end tests in place to make sure nothing major breaks.

    ~~I've made a start here but there are many examples still not covered, most notably the large example.rs/macro_example.rs. We should split that example into several more focused examples with better documentation as I can only imagine a new user is unable to really understand what features are available when the entire sink is thrown at them.~~ EDIT: example.rs has been split, macro_example.rs is left for future

    Feedback and suggestions are extremely welcome, this feels pretty hacky, but it's the most effective way I could think of getting a decent baseline without potentially introducing errors (by making internal code easier to test).

    opened by Ryman 20
  • Publish on crates.io

    Publish on crates.io

    In order to get nickel listed on cargo.io, we need to release a first version. Any hesitations to release a 0.1.0 from current master? @Ryman @SimonPersson ?

    opened by cburgdorf 18
  • Upgrade hyper/mime/url

    Upgrade hyper/mime/url

    The examples/template.rs example fails but it says it's deprecated? Anyways, the assertion fails because the line endings changed, probably because I'm on Windows and Git checks out with CRLF line endings by default.

    failures:
    
    ---- examples::template::renders_data stdout ----
            Parsed: port=58433 from "Listening on http://[::1]:58433"
    thread 'examples::template::renders_data' panicked at 'assertion failed: `(left == right)` (left: `"<html>\r\n
       <head>\r\n        <title>\r\n            nickel.rs - example\r\n        </title>\r\n    </head>\r\n    <body>\r\n    <h1>\r\n        Hello user!\r\n    </h1>\r\n    </body>\r\n</html>"`, right: `"<html>\n    <head>\n
         <title>\n            nickel.rs - example\n        </title>\n    </head>\n    <body>\n    <h1>\n        Hello user!\n    </h1>\n    </body>\n</html>"`)', tests\examples\template.rs:23
    Unparsed Stdout:
    

    Edit: forgot to add this:

    Closes #318

    opened by abonander 16
  • Example handling form data

    Example handling form data

    Complete example handling form data

    In regards to ticket number #240

    If you would like me to strip the cargo package before upload and just leave the "views" and "main.rs" just let me know.

    All that needs to be added now is the url parse.

    opened by xeaone 16
  • StaticFiles Middleware

    StaticFiles Middleware

    Tried to setup my nickel.rs site on ẁww.bennyklotz.at:3000

    Setup steps:

    $ cargo build --release
    $ ./target/release/website &
    

    After starting my binary in background everything worked fine, after I closed the ssh connection to my server and exited the shell "No data received" was returned.

    Here my coresponding src/main.rs file and screenshots without StaticFilesHandler:

    extern crate http;
    extern crate nickel;
    
    use std::io::net::ip::Ipv4Addr;
    use nickel::{
        Nickel, Request, Response
    };
    
    fn page (_request: &Request, response: &mut Response) {
            response.set_content_type("html");
            response.send("<h1>Hello Rust!</h1>");
    }
    
    fn main() {
        let mut server = Nickel::new();
    
        // server.utilize(Nickel::static_files("assets/"));
    
        server.get("/rust", page);
        server.listen(Ipv4Addr(134, 119, 3, 19), 3000);
    }
    

    After exiting from the ssh shell it's still working:

    http://s30.postimg.org/9g9k8qpkh/working_root.png http://s27.postimg.org/9cxm4cp8z/working_rust.png

    Here my coresponding src/main.rs and screenshots with StaticFilesHandler:

    extern crate http;
    extern crate nickel;
    
    use std::io::net::ip::Ipv4Addr;
    use nickel::{
        Nickel, Request, Response
    };
    
    fn page (_request: &Request, response: &mut Response) {
            response.set_content_type("html");
            response.send("<h1>Hello Rust!</h1>");
    }
    
    fn main() {
        let mut server = Nickel::new();
    
        server.utilize(Nickel::static_files("assets/"));
    
        server.get("/rust", page);
        server.listen(Ipv4Addr(134, 119, 3, 19), 3000);
    }
    

    Before exiting fom the ssh connection everything works:

    http://postimg.org/image/5v8l4o79r/ http://postimg.org/image/e20kw8xcf/

    After exiting from the ssh connection it doesn't work anymore:

    http://postimg.org/image/76cppvist/ http://postimg.org/image/jm9fjmc4t/

    opened by tak1n 15
  • Error compiling the project

    Error compiling the project

    Hi, I'm new to Rust. I'm very excited to try this new web framework backed by this new awesome language. I'm having problems compiling the project, when compiling rust-openssl specifically. This is what the error looks like:

    $ make all
    cargo build -v
         Running `rustc src/http/lib.rs --crate-name http --crate-type lib -g --out-dir /Users/jcivancevich/Desktop/floor/target/deps -L /Users/jcivancevich/Desktop/floor/target/deps -L /Users/jcivancevich/Desktop/floor/target/deps`
         Running `rustc lib.rs --crate-name openssl --crate-type lib -g --out-dir /Users/jcivancevich/Desktop/floor/target/deps -L /Users/jcivancevich/Desktop/floor/target/deps -L /Users/jcivancevich/Desktop/floor/target/deps`
         Running `rustc src/lib.rs --crate-name floor --crate-type lib -g --out-dir /Users/jcivancevich/Desktop/floor/target -L /Users/jcivancevich/Desktop/floor/target -L /Users/jcivancevich/Desktop/floor/target/deps`
       Compiling openssl v0.0.0 (https://github.com/sfackler/rust-openssl.git)
    Could not execute process `rustc lib.rs --crate-name openssl --crate-type lib -g --out-dir /Users/jcivancevich/Desktop/floor/target/deps -L /Users/jcivancevich/Desktop/floor/target/deps -L /Users/jcivancevich/Desktop/floor/target/deps` (status=101)
    --- stderr
    error: multiple input filenames provided
    

    Thanks for your great work! Hopefully, I can contribute to this project soon :)

    opened by ivancevich 14
  • Handling Sessions with an 'Environment'

    Handling Sessions with an 'Environment'

    This builds upon the ideas from #235 to add an 'environment' to each request. See https://github.com/nickel-org/nickel-auth/pull/1 for a related discussion which lead to this proposed change. Session would be really awkward to use correctly without something along the lines of this.

    cc @SimonPersson

    opened by Ryman 13
  • Should we fork major dependencies under nickel-org?

    Should we fork major dependencies under nickel-org?

    This would relieve some of the pre-1.0 churn since we can fix the upstream issues without constantly toggling between working and broken repos in the Cargo.toml file.

    The main con is that we'll need to merge upstream changes pretty frequently, but at least we'd have some control over the timing of when things get merged?

    opened by Ryman 13
  • feat(server): return `ListeningServer` from `Nickel::listen`

    feat(server): return `ListeningServer` from `Nickel::listen`

    Related to #328.

    The tests within this repo are a bit of a hack (require shelling out to subprocesses involving cargo), with this change we can instead make it easier to integration test a server (or multiple instances of one) all within the same process which should be easier and faster.

    The code within the integration test example would get tested using a normal cargo test, but since it's in our example files I had to use a workaround to get it compiled directly into our integration test runner.

    BREAKING CHANGE: This changes the return type of Nickel::listen, you can add an unwrap() to the call to maintain previous semantics.

    opened by Ryman 12
  • "Finalizer" middleware

    I am working through a relatively full featured backend api server, which includes in the middleware stack, among other things, things like:

    • api keys
    • logging

    let's walk through the problem:

    the api keys middleware will check validity of the api key- if good, it calls next_middleware(), if not good, it calls send(), without calling next_middleware.

    But, I also have a logging middleware that should track both the incoming URL and the outgoing status code. now, as per spect, next_middleware ends the middleware call tree, but, I need this finalizer code (logging) to execute.

    thoughts?

    opened by pnathan 0
  • fix(static_file_handler): Support for blank spaces and percent encodi…

    fix(static_file_handler): Support for blank spaces and percent encodi…

    Summary

    Adds handling for whitespaces in url for static files handler.

    Issue

    #405

    Note

    Im really new at Rust, and even more with ownership and low level memory handling, so probably i've made some mistakes in the way i changed this to a String. I'm more than open to hear suggestions on how to do this any better. Fix inspired by https://github.com/lawliet89/nickel.rs/commit/f1c03e27c47366c974322e9db2904edd0ffcb9de

    opened by hdf1986 2
  • What is the good threads count to setup ?

    What is the good threads count to setup ?

    Hi,

    How works the multi-threading in the Nickel lib? what is the good value to set in the option thread_count?

    Related to: https://github.com/clintnetwork/lucid/issues/16

    Thank you

    opened by thisisclint21 0
  • How to use handler in impl

    How to use handler in impl

    Hi,

    I would like to use a custom handler or a logger in the same impl, but i've this error:

    44 |         server.utilize(self.logger);
       |                             ^^^^^^ help: use parentheses to call the method: `logger(...)
    

    Thanks

    opened by thisisclint21 6
  • StaticFilesHandler from binary resource

    StaticFilesHandler from binary resource

    Hey,

    In the goal to publish a binary that can include a web page, I try to use StaticFilesHandler with included resources files, do you think there are an easy way to achieve this ?

    Cheers

    opened by thisisclint21 12
Static Web Server - a very small and fast production-ready web server suitable to serve static web files or assets

Static Web Server (or SWS abbreviated) is a very small and fast production-ready web server suitable to serve static web files or assets.

Jose Quintana 496 Jan 2, 2023
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

Actix 16.3k Jan 8, 2023
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

null 6.1k Dec 27, 2022
A web framework for Rust.

Rocket Rocket is an async web framework for Rust with a focus on usability, security, extensibility, and speed. #[macro_use] extern crate rocket; #[g

Sergio Benitez 19.5k Jan 8, 2023
A lightweight web framework built on hyper, implemented in Rust language.

Sapper Sapper, a lightweight web framework, written in Rust. Sapper focuses on ergonomic usage and rapid development. It can work with stable Rust. Sa

Daogang Tang 622 Oct 27, 2022
Web framework in Rust

Rouille, a Rust web micro-framework Rouille is a micro-web-framework library. It creates a listening socket and parses incoming HTTP requests from cli

Pierre Krieger 840 Jan 1, 2023
A fast, boilerplate free, web framework for Rust

Tower Web A web framework for Rust with a focus on removing boilerplate. API Documentation Tower Web is: Fast: Fully asynchronous, built on Tokio and

Carl Lerche 969 Dec 22, 2022
Sincere is a micro web framework for Rust(stable) based on hyper and multithreading

The project is no longer maintained! Sincere Sincere is a micro web framework for Rust(stable) based on hyper and multithreading. Style like koa. The

null 94 Oct 26, 2022
Salvo is a powerful and simplest web server framework in Rust world

Salvo is an extremely simple and powerful Rust web backend framework. Only basic Rust knowledge is required to develop backend services.

Salvo 1.2k Jan 5, 2023
The light web framework for Rust.

Rusty Web Rusty web is a simple to use, fully customizable lightweight web framework for rust developers. Learn rusty web Installation [dependencies]

Tej Magar 5 Feb 27, 2024
A flexible web framework that promotes stability, safety, security and speed.

A flexible web framework that promotes stability, safety, security and speed. Features Stability focused. All releases target stable Rust. This will n

Gotham 2.1k Jan 3, 2023
Handlebars middleware for Iron web framework

handlebars-iron Handlebars middleware for the Iron web framework. This library, together with handlebars, iron and hyper, works on both stable and nig

Ning Sun 118 Jun 28, 2022
JSON Web Token implementation in Rust.

Frank JWT Implementation of JSON Web Tokens in Rust. Algorithms and features supported HS256 HS384 HS512 RS256 RS384 RS512 ES256 ES384 ES512 Sign Veri

Alex Maslakov 246 Dec 27, 2022
Source Code for 'Practical Rust Web Projects' by Shing Lyu

Apress Source Code This repository accompanies Practical Rust Web Projects by Shing Lyu (Apress, 2021). Download the files as a zip using the green bu

Apress 44 Nov 17, 2022
A web application completely written in Rust. 🌍

WebApp.rs A web application completely written in Rust Target of this project is to write a complete web application including backend and frontend wi

Sascha Grunert 2.1k Dec 30, 2022
Web Server made with Rust - for learning purposes

Web Server made with Rust - for learning purposes

Lílian 2 Apr 25, 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
VRS is a simple, minimal, free and open source static web server written in Rust

VRS is a simple, minimal, free and open source static web server written in Rust which uses absolutely no dependencies and revolves around Rust's std::net built-in utility.

null 36 Nov 8, 2022
Example Blog using Rust, Actix Web, HTMX, Mustache

Actix Blog An example blog built with Actix. It uses htmx and handlebar templates. Running To run the blog, you need to have a recent version of Rust

Dru Jensen 2 Nov 11, 2022