nickel.rs
Web Application Framework
For Rust
@cburgdorf
Software Gardener
at CouchCommerce
@cburgdorf
Teach People
at Thoughtram
@cburgdorf
Globetrotter
by bike
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
"Rust is a systems programming language that runs blazingly fast, prevents almost all crashes*, and eliminates data races."
* In theory. Rust is a work-in-progress and may do anything it likes up to and including eating your laundry.
Control / Performance
Safety
C
C++
Rust
Go
Java
ML
Haskell
Features
Write a browser
Write an operating system
Write a kernel
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. 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?
MARKET SCREENING
WHAT DO WE LOOK FOR?
Express.rs
☹
Build it!
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. 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 log (r: &Request, _r: &mut Response) -> Result<Action, NickelError> {
println!("logging request: {}", r.origin.request_uri);
Ok(Continue)
}
server.utilize(FromFn::new(log));
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);
}
Templates: mustache
<html>
<body>
<h1>
Hello {{ name }}!
</h1>
</body>
</html>
extern crate nickel;
extern crate http;
use nickel::{ Nickel, Request, Response };
use std::io::net::ip::Ipv4Addr;
use std::collections::HashMap;
fn main() {
let mut server = Nickel::new();
fn handler (_request: &Request, response: &mut Response) {
let mut data = HashMap::<&str, &str>::new();
data.insert("name", "user");
response.render("examples/assets/template.tpl", &data);
}
server.get("/", handler);
server.listen(Ipv4Addr(127, 0, 0, 1), 6767);
}
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
Demo
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
Outline
1. Rust Why yet another language?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
2. Why Why did I start this project?
3. Overview How does it work?
4. Demo See it in action!
5. Future Where do we go from here?
Future Plans
More Middleware
Better Testing
Mounting
Tons Of Cleanup
Logo
Closures
Contribute?
Thanks.
@cburgdorf
github.com/cburgdorf
slides.com/cburgdorf/merhaba-nickelrs
merhaba nickel.rs
By cburgdorf
merhaba nickel.rs
- 2,999