All Projects → danclive → Sincere

danclive / Sincere

Licence: mit
Sincere is a micro web framework for Rust(stable) based on hyper and multithreading

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Sincere

Cakephp
CakePHP: The Rapid Development Framework for PHP - Official Repository
Stars: ✭ 8,453 (+9189.01%)
Mutual labels:  web-framework
Automatedlab
AutomatedLab is a provisioning solution and framework that lets you deploy complex labs on HyperV and Azure with simple PowerShell scripts. It supports all Windows operating systems from 2008 R2 to 2019, some Linux distributions and various products like AD, Exchange, PKI, IIS, etc.
Stars: ✭ 1,194 (+1212.09%)
Mutual labels:  hyper
Jkmvc
Jkmvc is an elegant, powerful and lightweight MVC & ORM framework built using kotlin. It aims to be swift, secure, and small. It will turn java's heavy development into kotlin's simple pleasure. No spring.
Stars: ✭ 86 (-5.49%)
Mutual labels:  web-framework
Appnet
A Network Server Extension For PHP
Stars: ✭ 72 (-20.88%)
Mutual labels:  epoll
1m Go Tcp Server
benchmarks for implementation of servers which support 1 million connections
Stars: ✭ 1,193 (+1210.99%)
Mutual labels:  epoll
Tcpsocks
Redirect traffic to SOCKS5 server with iptables, epoll based, single threaded.
Stars: ✭ 78 (-14.29%)
Mutual labels:  epoll
Ktor
Framework for quickly creating connected applications in Kotlin with minimal effort
Stars: ✭ 9,190 (+9998.9%)
Mutual labels:  web-framework
Piping Server Rust
Infinitely transfer between any device over pure HTTP, designed for everyone using Unix pipe and even for browser users
Stars: ✭ 88 (-3.3%)
Mutual labels:  hyper
Envelop.c
🌊 Thread-less, event-loop based tiny http-server from scratch using epoll. Learning Purpose.
Stars: ✭ 75 (-17.58%)
Mutual labels:  epoll
Ofbiz Plugins
Apache OFBiz is an open source product for the automation of enterprise processes. It includes framework components and business applications for ERP, CRM, E-Business/E-Commerce, Supply Chain Management and Manufacturing Resource Planning. OFBiz provides a foundation and starting point for reliable, secure and scalable enterprise solutions.
Stars: ✭ 83 (-8.79%)
Mutual labels:  web-framework
Fastplaz
FastPlaz - Pascal Web Framework
Stars: ✭ 72 (-20.88%)
Mutual labels:  web-framework
Hyper
🧛🏻‍♂️ Dark theme for Hyper
Stars: ✭ 74 (-18.68%)
Mutual labels:  hyper
Butterfly
🔥 蝴蝶--【简单】【稳定】【好用】的 Python web 框架🦋 除 Python 2.7,无其他依赖; 🦋 butterfly 是一个 RPC 风格 web 框架,同时也是微服务框架,自带消息队列通信机制实现分布式
Stars: ✭ 82 (-9.89%)
Mutual labels:  web-framework
Foal
Elegant and all-inclusive Node.Js web framework based on TypeScript. 🚀.
Stars: ✭ 1,176 (+1192.31%)
Mutual labels:  web-framework
Prairie
Get web applications growing in R
Stars: ✭ 86 (-5.49%)
Mutual labels:  web-framework
Cuba
CUBA Platform is a high level framework for enterprise applications development
Stars: ✭ 1,114 (+1124.18%)
Mutual labels:  web-framework
Toruk
Go web 开发脚手架
Stars: ✭ 78 (-14.29%)
Mutual labels:  web-framework
Dotfiles
My configuration files
Stars: ✭ 89 (-2.2%)
Mutual labels:  hyper
Tapestry 5
Mirror of Apache Tapestry 5
Stars: ✭ 87 (-4.4%)
Mutual labels:  web-framework
Hyper Snazzy
Elegant Hyper theme with bright colors
Stars: ✭ 1,248 (+1271.43%)
Mutual labels:  hyper

The project is no longer maintained!

Sincere

crates.io Build Status MIT licensed Released API docs

Sincere is a micro web framework for Rust(stable) based on hyper and multithreading. Style like koa. The same, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs. Sincere does not bundle any middleware within core, and provides an elegant suite of methods that make writing servers fast and enjoyable. Here is an example of a simple application:

extern crate sincere;

use sincere::App;

fn main() {
    let mut app = App::new();

    app.get("/", |context| {
        context.response.from_text("Hello world!").unwrap();
    });

    app.run("127.0.0.1:8000").unwrap();
}

Don't forget add this to your Cargo.toml:

[dependencies]
sincere = "0.7.0-alpha.1"

Build and run, then, visiting http://127.0.0.1:8000/, you will see Hello world on the screen.

API documentation:

Guide

Routing

app.add("GET", "/user", ...);

app.get("/user", ...);

app.get("/user/{id:[0-9]+}", ...);

app.post("/user", ...);

app.put("/user/{id:[0-9]+}", ...);

app.delete("/user/{id:[0-9]+}", ...);

app.options("/", ...);

app.connect("/", ...);

app.head("/", ...);

Route Group

use sincere::App;
use sincere::Group;

fn main() {
    let mut app = App::new();

    app.get("/", |context| {
        context.response.from_text("Hello world!").unwrap();
    });

    let mut user_group = Group::new("/user");

    // /user
    user_group.get("/", ...);
    // /user/123
    app.get("/{id:[0-9]+}", ...);

    app.mount_group(user_group::handle);

    app.run("127.0.0.1:8000");
}
use sincere::App;
use sincere::Group;
use sincere::Context;

pub struct User;

impl User {
    pub fn list(mut context: &mut Context) {
        ...
    }

    pub fn detail(mut context: &mut Context) {
        ...
    }

    pub fn handle() -> Group {
        let mut group = Group::new("/user");

        group.get("/", Self::list);
        group.get("/{id:[0-9]+}", Self::detail);

        group
    }
}

fn main() {
    let mut app = App::new();

    app.get("/", |context| {
        context.response.from_text("Hello world!").unwrap();
    });

    app.mount(User::handle());

    app.run("127.0.0.1:8000");
}

Middleware

use sincere::App;

fn main() {
    let mut app = App::new();

    app.begin(|context| {
        ...
    });

    app.before(|context| {
        ...
    });

    app.after(|context| {
        ...
    });

    app.finish(|context| {
        ...
    });


    app.get("/", |context| {
        context.response.from_text("Hello world!").unwrap();
    });

    app.run("127.0.0.1:8000");
}
...
app.begin(...).begin(...);

app.begin(...).finish(...);

app.begin(...).before(...).after(...).finish(...);
...
app.get("/", |context| {
    context.response.from_text("Hello world!").unwrap();
}).before(...).after(...);
let mut group = Group::new("/user");

group.before(...).after(...);

group.get("/", |context| {
    context.response.from_text("Hello world!").unwrap();
}).before(...).after(...);
pub fn auth(context: &mut Context) {
    if let Some(token) = context.request.get_header("Token") {
        match token::verify_token(token) {
            Ok(id) => {
                context.contexts.insert("id".to_owned(), Value::String(id));
            },
            Err(err) => {
                context.response.from_text("").unwrap();
                context.stop();
            }
        }
    } else {
        context.response.status_code(401);
        context.stop();
    }
}

app.post("/article", ...).before(auth);

group.post("/", ...).before(auth);

pub fn cors(app: &mut App) {

    app.begin(move |context| {
        if context.request.method() == &Method::Options {
            context.response
            .status_code(204)
            .header(("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS"));

            context.stop();
        }
    });

    app.finish(move |context| {
        context.response
        .header(("Access-Control-Allow-Origin", "*"))
        .header(("Access-Control-Allow-Headers", "content-type, token"));
    });
}

app.use_middleware(cors);

Path Parameters

app.get("/user/{id}", |context| {
    let id = context.request.param("id").unwrap();
});

app.get("/user/{id:[0-9]+}", |context| {
    let id = context.request.param("id").unwrap();
});

app.get("/user/{id:[a-z0-9]{24}}", |context| {
    let id = context.request.param("id").unwrap();
});

Query Parameters

/article?per_page=10&page=1

app.get("/article", |content| {
    let page = context.request.query("page").unwrap_or("1");
    let per_page = context.request.query("per_page").unwrap_or("10");
});

Bind Json

serde_derive = "1.0"

[dependencies.serde_json]
version = "1.0"
features = ["preserve_order"]
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
app.post("/article", |content| {

    #[derive(Deserialize, Debug)]
    struct New {
        title: String,
        image: Vec<String>,
        content: String
    }

    let new_json = context.request.bind_json::<New>().unwrap();

    // some code

    let return_json = json!({
        "article_id": 123
    });

    context.response.from_json(return_json).unwrap();
});

Get and set headers, http status code

app.get("/", |context| {
    let token = context.request.header("Token").unwrap_or("none".to_owned());

    context.response.from_text("Hello world!").status_code(200).header(("Hello", "World")).unwrap();
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].