Code Monkey home page Code Monkey logo

floor's Introduction

Floor

Floor is supposed to be a simple and lightweight foundation for web applications written in Rust. It's API is inspired by the popular express framework for JavaScript.

Some of the features are:

  • Easy handlers: A handler is just a function that takes a Request and ResponseWriter
  • Variables in routes. Just write my/route/:someid
  • Easy parameter access: request.params.get(&"someid")
  • simple wildcard routes: /some/*/route
  • double wildcard routes: /a/**/route

##Jump to the Full Documentation

#Getting started The easiest way to get started is to get the example running and play around with it. Let's do that real quick!

##Clone the repository

git clone --recursive https://github.com/cburgdorf/Floor.git

##Build Floor

make all

##Run the example

make run

Then try localhost:6767/user/4711 and localhost:6767/bar

##Take a look at the example code Here is how sample server in example.rs looks like:

extern crate http;
extern crate floor;

use floor::{ Floor, Request };
use http::server::{ ResponseWriter };

fn main() {

    let mut server = Floor::new();
    
    // we would love to use a closure for the handler but it seems to be hard
    // to achieve with the current version of rust.

    fn user_handler (request: Request, response: &mut ResponseWriter) {
        let _ = write!(response, "This is user: {}", request.params.get(&"userid".to_string()));
    };

    // go to http://localhost:6767/user/4711 to see this route in action
    server.get("/user/:userid", user_handler);

    fn bar_handler (request: Request, response: &mut ResponseWriter) { 
        response.write("This is the /bar handler".as_bytes()); 
    };

    // go to http://localhost:6767/bar to see this route in action
    server.get("/bar", bar_handler);

    fn simple_wildcard (request: Request, response: &mut ResponseWriter) { 
        response.write("This matches /some/crazy/route but not /some/super/crazy/route".as_bytes()); 
    };

    // go to http://localhost:6767/some/crazy/route to see this route in action
    server.get("/some/*/route", simple_wildcard);

    fn double_wildcard (request: Request, response: &mut ResponseWriter) { 
        response.write("This matches /a/crazy/route and also /a/super/crazy/route".as_bytes()); 
    };

    // go to http://localhost:6767/a/nice/route or http://localhost:6767/a/super/nice/route to see this route in action
    server.get("/a/**/route", double_wildcard);

    fn post_handler (request: Request, response: &mut ResponseWriter) { 
        response.write("This matches a POST request to /a/post/request".as_bytes()); 
    };

    // go to http://localhost:6767/a/post/request to see this route in action
    server.post("/a/post/request", post_handler);

    server.listen(6767);
}

##Jump to the Full Documentation

##License

Floor is open source and licensed with the MIT license

##Contributing

I would love to find a helping hand. Especially if you know Rust, because I don't :) There is list of open issues right here on github. And hey, did you know you can also contribute by just starring the project here on github :)

floor's People

Contributors

cburgdorf avatar jhlllnd avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.