nickel.rs


Web Application Framework
For Rust












@cburgdorf
Software Gardener
at CouchCommerce












@cburgdorf
Teach People
at Thoughtram












@cburgdorf
Globetrotter
by bike


 Outline  

 1. Why Why did I start this project? 

 2. Overview How does it work? 

 3. Demo  See it in action! 

 4. Future  Where do we go from here? 


 Outline  

 1. Why Why did I start this project? 

 2. Overview How does it work? 

 3. Demo  See it in action! 

 4. Future  Where do we go from here? 






 http://ninya.io 






 http://operations.ninya.io 




 ninya.io is all Node.js 


 operations.ninya.io is all Go 


 Can operations.ninya.io be Rust? 




 ninya.io is all Node.js 


 operations.ninya.io is all Go 


 Can operations.ninya.io be Rust? 




 MARKET SCREENING 
WHAT DO WE LOOK FOR?

Express.rs

DOES IT EXIST?



Build it!


 Outline  

 1. Why  Why did I start this project? 

 2. Overview How does it work? 

 3. Demo  See it in action! 

 4. Future  Where do we go from here? 


 Outline  

 1. Why  Why did I start this project? 

 2. Overview How does it work? 

 3. Demo  See it in action! 

 4. Future  Where do we go from here? 



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) { 
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
} 



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) { 
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
} 



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) { 
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
} 



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) { 
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
} 



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) { 
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
} 



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) { 
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world");
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Hello World 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Http Verbs 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Http Verbs 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.put("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Http Verbs 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.post("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Http Verbs 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.delete("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Flexible Routing 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/bar", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}

matches: http://localhost:6767/bar



 Flexible Routing 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/a/*/d", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}

matches: http://localhost:6767/a/b/d

NOT matches: http://localhost:6767/a/b/c/d



 Flexible Routing 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/a/**/d", a_handler); 
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}

matches: http://localhost:6767/a/b/d

also matches: http://localhost:6767/a/b/c/d



 Middleware 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    server.utilize(Nickel::static_files("examples/assets/"));
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/a/**/d", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



 Middleware: Static Files 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

fn main() {
    let mut server = Nickel::new();
    
    server.utilize(Nickel::static_files("examples/assets/"));
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/a/**/d", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}


 Middleware: JSON Body Parser 

extern crate serialize;
extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

#[deriving(Decodable, Encodable)]
struct Person {
    firstname: String,
    lastname:  String,
}

fn main() {
    let mut server = Nickel::new();
    
    server.utilize(Nickel::json_body_parser());

    fn post_handler (request: &Request, response: &mut Response) { 
        let person = request.json_as::<Person>().unwrap();
        let text = format!("Hello {} {}", person.firstname, person.lastname);
        response.send(text.as_slice()); 
    }
    
    server.post("/a/post/request", post_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}


 Middleware: JSON Body Parser 

extern crate serialize;
extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

#[deriving(Decodable, Encodable)]
struct Person {
    firstname: String,
    lastname:  String,
}

fn main() {
    let mut server = Nickel::new();
    
    server.utilize(Nickel::json_body_parser());

    fn post_handler (request: &Request, response: &mut Response) { 
        let person = request.json_as::<Person>().unwrap();
        let text = format!("Hello {} {}", person.firstname, person.lastname);
        response.send(text.as_slice()); 
    }
    
    server.post("/a/post/request", post_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}


 Middleware: JSON Body Parser 

extern crate serialize;
extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

#[deriving(Decodable, Encodable)]
struct Person {
    firstname: String,
    lastname:  String,
}

fn main() {
    let mut server = Nickel::new();
    
    server.utilize(Nickel::json_body_parser());

    fn post_handler (request: &Request, response: &mut Response) { 
        let person = request.json_as::<Person>().unwrap();
        let text = format!("Hello {} {}", person.firstname, person.lastname);
        response.send(text.as_slice()); 
    }
    
    server.post("/a/post/request", post_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}


 Middleware: JSON Body Parser 

extern crate serialize;
extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response };

#[deriving(Decodable, Encodable)]
struct Person {
    firstname: String,
    lastname:  String,
}

fn main() {
    let mut server = Nickel::new();
    
    server.utilize(Nickel::json_body_parser());

    fn post_handler (request: &Request, response: &mut Response) { 
        let person = request.json_as::<Person>().unwrap();
        let text = format!("Hello {} {}", person.firstname, person.lastname);
        response.send(text.as_slice()); 
    }
    
    server.post("/a/post/request", post_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}



Custom Middleware?



 Middleware: Custom 

extern crate nickel;

use std::io::net::ip::Ipv4Addr;
use nickel::{ Nickel, Request, Response, Action };

fn main() {
    let mut server = Nickel::new();

    fn logger (request: &Request, _response: &mut Response) -> Action {
        println!("logging request: {}", request.origin.request_uri);
        Continue
    }
    
    server.utilize(FromFn::new(logger));
    
    fn a_handler (_request: &Request, response: &mut Response) {
        response.send("hello world"); 
    }

    server.get("/a/**/d", a_handler);
    server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}


 Outline  

 1. Why  Why did I start this project? 

 2. Overview How does it work? 

 3. Demo  See it in action! 

 4. Future  Where do we go from here? 


 Outline  

 1. Why  Why did I start this project? 

 2. Overview How does it work? 

 3. Demo  See it in action! 

 4. Future  Where do we go from here? 


Demo


 Outline  

 1. Why  Why did I start this project? 

 2. Overview How does it work? 

 3. Demo  See it in action! 

 4. Future  Where do we go from here? 


 Outline  

 1. Why  Why did I start this project? 

 2. Overview How does it work? 

 3. Demo  See it in action! 

 4. Future  Where do we go from here? 

 Future Plans 

More Middleware URL Encoding Mounting Tons Of Cleanup Error Handling Rendering Engine LOGO
 Contribute? 



Thanks.





@cburgdorf
github.com/cburgdorf
slide.es/cburgdorf/introducing-nickel-web-framework
Made with Slides.com