An expressjs inspired web framework for Rust

Related tags

nickel.rs
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
Issues
  • [WIP] Make it build with Rust 1.0.0-alpha

    [WIP] Make it build with Rust 1.0.0-alpha

    opened by rgs1 42
  • Does not compile under Rust 1.0.0 Alpha

    Does not compile under Rust 1.0.0 Alpha

    The library doesn't compile in 1.0.0 alpha. The errors are too long to post here, but I can create a pastebin if necessary.

    opened by zrneely 30
  • 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 vokeio 16
  • feat(nickel): add options to Nickel, redux

    feat(nickel): add options to Nickel, redux

    The original PR (#277) appears to be dead. @ixjf

    opened by euclio 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
  • "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
  • EventSource Server

    EventSource Server

    Hi,

    How to create an event source server with Nickel? and also how to set the text/event-stream mime-type?

    Best regards

    opened by clintnetwork 0
  • 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 clintnetwork 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 clintnetwork 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 clintnetwork 12
  • Router cannot match while the HTTP Path is AbsoluteUri

    Router cannot match while the HTTP Path is AbsoluteUri

    Add middleware for every request

    server.utilize(middleware! { | request |
        println!("logging request from middleware! macro: {:?}", request.origin.uri);
    });
    

    Handle a route

    server.get('/',  middleware!("Yes, got it!");
    

    start server

    let _ = server.listen("127.0.0.1:8080");
    

    visit http://localhost:8080, get corrent response from server, and terminal display:

    logging request from middleware! macro: AbsolutePath("/")
    

    But browser got 404 while visiting with a domain(by SwitchyOmega chrome plugin), the HTTP request header begin with:

    GET http://xxx.com/ HTTP/1.1
    

    And log middleware output the message:

    logging request from middleware! macro: AbsoluteUri("http://xxx.com/")
    
    opened by colorhook 0
  • Matcher has problem matching text

    Matcher has problem matching text

    Here's a route I made

        server.get("/test/:id", middleware!{|req| 
            let id = req.param("id").unwrap();
            format!("{}", id.to_string())
        });
    

    If you try to browse the url /test/fun.js get param will only match fun and not fun.js. Also if you want to browse the url: /test/fun:time.js It will not match anything and fail with NotFound.

    opened by llacroix 4
  • Unsatisfactory error recovery story with `Response::end()`

    Unsatisfactory error recovery story with `Response::end()`

    If Response::end() fails, the response is consumed so there's no way to create a NickelError without unsafe (except that NickelError has all fields public so it's possible to bypass the constructor completely). The reasoning for unsafe on NickelError::without_response() talks about deadlock if the response is not flushed, which is what the user is trying to do by calling Response::end(). So if the flush fails, what are we meant to do? It seems like a guaranteed deadlock since we can't call bail() now.

    P-mid E-easy 
    opened by abonander 3
  • Develop SSL Strategy/Story

    Develop SSL Strategy/Story

    We inadvertently disabled SSL support in the upgrade to hyper 0.10 (sadly, no one noticed). Hyper 0.11 does not have native SSL support.

    T-feature 
    opened by jolhoeft 5
A starter template for actix-web projects that feels very Django-esque. Avoid the boring stuff and move faster.

Jelly A.K.A, the actix-web starter you probably wish you had. This is provided as-is, and anyone is free to extend it or rework it as they desire - ju

SecretKeys 85 Sep 17, 2021
An expressjs inspired web framework for Rust

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

null 2.9k Sep 18, 2021
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 960 Sep 10, 2021
A framework that allows anyone to create an Urbit Chatbot with only a few lines of code.

Urbit Chatbot Framework A framework that allows anyone to create an Urbit Chatbot with only a few lines of code. The Urbit Chatbot Framework takes car

Robert Kornacki 18 Jul 6, 2021
Extension for actix-web to validate user permissions

actix-web-grants Extension for actix-web to validate user permissions. To check user access to specific services, you can use built-in proc-macro, Per

Artem Medvedev 50 Sep 13, 2021
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 699 Sep 18, 2021
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 6k Sep 15, 2021
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 14.7k Sep 17, 2021
web browser as a language server

web-browser-lsp A toy program that implements a text-based web browser as a language server. Motivation My favorite progrmming tools are neovim, tmux

octaltree 10 Jun 12, 2021
GraphQL server library for Rust

GraphQL server library for Rust GraphQL is a data query language developed by Facebook intended to serve mobile and web application frontends. Juniper

GraphQL Rust 4k Sep 9, 2021
RiteRaft - A raft framework, for regular people

RiteRaft - A raft framework, for regular people This is an attempt to create a layer on top of tikv/raft-rs, that is easier to use and implement. This

Rite Database 197 Sep 2, 2021
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 92 Aug 22, 2021
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 75 Aug 21, 2021
Rust templating with Handlebars

handlebars-rust Handlebars templating language implemented in Rust and for Rust. Handlebars-rust is the template engine that renders the official Rust

Ning Sun 732 Sep 11, 2021
REST-like API micro-framework for Rust. Works with Iron.

Table of Contents What is Rustless? Usage warning Basic Usage Complex example Mounting Parameters validation and coercion Use JSON Schema Query string

Rustless 604 Sep 2, 2021
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 616 Aug 26, 2021
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 545 Sep 9, 2021
A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. :zap::crab:

binserve ⚡ ?? A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. ?? UPDATE: N

Mufeed VH 480 Sep 15, 2021
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 21 Aug 24, 2021