{"id":13440258,"url":"https://github.com/danclive/sincere","last_synced_at":"2025-03-20T09:32:39.829Z","repository":{"id":57634640,"uuid":"79920981","full_name":"danclive/sincere","owner":"danclive","description":"Sincere is a micro web framework for Rust(stable) based on hyper and multithreading","archived":true,"fork":false,"pushed_at":"2020-10-17T07:29:53.000Z","size":204,"stargazers_count":98,"open_issues_count":3,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T09:18:17.300Z","etag":null,"topics":["epoll","http","hyper","rust","web-framework"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danclive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-24T14:53:07.000Z","updated_at":"2025-01-04T23:16:01.000Z","dependencies_parsed_at":"2022-09-06T04:02:44.610Z","dependency_job_id":null,"html_url":"https://github.com/danclive/sincere","commit_stats":null,"previous_names":["mitum/sincere"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fsincere","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fsincere/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fsincere/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danclive%2Fsincere/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danclive","download_url":"https://codeload.github.com/danclive/sincere/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244585941,"owners_count":20476845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["epoll","http","hyper","rust","web-framework"],"created_at":"2024-07-31T03:01:21.128Z","updated_at":"2025-03-20T09:32:39.484Z","avatar_url":"https://github.com/danclive.png","language":"Rust","funding_links":[],"categories":["Libraries","库 Libraries","Rust","库"],"sub_categories":["Web programming","网络编程 Web programming","网页编程","web编程 Web programming"],"readme":"# The project is no longer maintained！\n\n# Sincere\n\n[![crates.io](https://meritbadge.herokuapp.com/sincere)](https://crates.io/crates/sincere)\n[![Build Status](https://travis-ci.org/danclive/sincere.svg?branch=master)](https://travis-ci.org/danclive/sincere)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n[![Released API docs](https://docs.rs/sincere/badge.svg)](https://docs.rs/sincere)\n\nSincere 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.\nHere is an example of a simple application:\n\n```rust\nextern crate sincere;\n\nuse sincere::App;\n\nfn main() {\n    let mut app = App::new();\n\n    app.get(\"/\", |context| {\n        context.response.from_text(\"Hello world!\").unwrap();\n    });\n\n    app.run(\"127.0.0.1:8000\").unwrap();\n}\n```\nDon't forget add this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nsincere = \"0.7.0-alpha.1\"\n```\nBuild and run, then, visiting `http://127.0.0.1:8000/`, you will see `Hello world` on the screen.\n\n## API documentation: \n\n- [master](https://docs.rs/sincere)\n\n## Guide\n\n### Routing\n\n```rust\napp.add(\"GET\", \"/user\", ...);\n\napp.get(\"/user\", ...);\n\napp.get(\"/user/{id:[0-9]+}\", ...);\n\napp.post(\"/user\", ...);\n\napp.put(\"/user/{id:[0-9]+}\", ...);\n\napp.delete(\"/user/{id:[0-9]+}\", ...);\n\napp.options(\"/\", ...);\n\napp.connect(\"/\", ...);\n\napp.head(\"/\", ...);\n\n```\n\n### Route Group\n\n```rust\nuse sincere::App;\nuse sincere::Group;\n\nfn main() {\n    let mut app = App::new();\n\n    app.get(\"/\", |context| {\n        context.response.from_text(\"Hello world!\").unwrap();\n    });\n\n    let mut user_group = Group::new(\"/user\");\n\n    // /user\n    user_group.get(\"/\", ...);\n    // /user/123\n    app.get(\"/{id:[0-9]+}\", ...);\n\n    app.mount_group(user_group::handle);\n\n    app.run(\"127.0.0.1:8000\");\n}\n```\n\n```rust\nuse sincere::App;\nuse sincere::Group;\nuse sincere::Context;\n\npub struct User;\n\nimpl User {\n    pub fn list(mut context: \u0026mut Context) {\n        ...\n    }\n\n    pub fn detail(mut context: \u0026mut Context) {\n        ...\n    }\n\n    pub fn handle() -\u003e Group {\n        let mut group = Group::new(\"/user\");\n\n        group.get(\"/\", Self::list);\n        group.get(\"/{id:[0-9]+}\", Self::detail);\n\n        group\n    }\n}\n\nfn main() {\n    let mut app = App::new();\n\n    app.get(\"/\", |context| {\n        context.response.from_text(\"Hello world!\").unwrap();\n    });\n\n    app.mount(User::handle());\n\n    app.run(\"127.0.0.1:8000\");\n}\n```\n\n### Middleware\n\n```rust\nuse sincere::App;\n\nfn main() {\n    let mut app = App::new();\n\n    app.begin(|context| {\n        ...\n    });\n\n    app.before(|context| {\n        ...\n    });\n\n    app.after(|context| {\n        ...\n    });\n\n    app.finish(|context| {\n        ...\n    });\n\n\n    app.get(\"/\", |context| {\n        context.response.from_text(\"Hello world!\").unwrap();\n    });\n\n    app.run(\"127.0.0.1:8000\");\n}\n```\n\n```rust\n...\napp.begin(...).begin(...);\n\napp.begin(...).finish(...);\n\napp.begin(...).before(...).after(...).finish(...);\n...\n```\n\n```rust\napp.get(\"/\", |context| {\n    context.response.from_text(\"Hello world!\").unwrap();\n}).before(...).after(...);\n```\n\n```rust\nlet mut group = Group::new(\"/user\");\n\ngroup.before(...).after(...);\n\ngroup.get(\"/\", |context| {\n    context.response.from_text(\"Hello world!\").unwrap();\n}).before(...).after(...);\n```\n\n```rust\npub fn auth(context: \u0026mut Context) {\n    if let Some(token) = context.request.get_header(\"Token\") {\n        match token::verify_token(token) {\n            Ok(id) =\u003e {\n                context.contexts.insert(\"id\".to_owned(), Value::String(id));\n            },\n            Err(err) =\u003e {\n                context.response.from_text(\"\").unwrap();\n                context.stop();\n            }\n        }\n    } else {\n        context.response.status_code(401);\n        context.stop();\n    }\n}\n\napp.post(\"/article\", ...).before(auth);\n\ngroup.post(\"/\", ...).before(auth);\n\n```\n\n```rust\npub fn cors(app: \u0026mut App) {\n\n    app.begin(move |context| {\n        if context.request.method() == \u0026Method::Options {\n            context.response\n            .status_code(204)\n            .header((\"Access-Control-Allow-Methods\", \"GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS\"));\n\n            context.stop();\n        }\n    });\n\n    app.finish(move |context| {\n        context.response\n        .header((\"Access-Control-Allow-Origin\", \"*\"))\n        .header((\"Access-Control-Allow-Headers\", \"content-type, token\"));\n    });\n}\n\napp.use_middleware(cors);\n```\n\n### Path Parameters\n\n```rust\napp.get(\"/user/{id}\", |context| {\n    let id = context.request.param(\"id\").unwrap();\n});\n\napp.get(\"/user/{id:[0-9]+}\", |context| {\n    let id = context.request.param(\"id\").unwrap();\n});\n\napp.get(\"/user/{id:[a-z0-9]{24}}\", |context| {\n    let id = context.request.param(\"id\").unwrap();\n});\n```\n\n### Query Parameters\n\n`/article?per_page=10\u0026page=1`\n\n```rust\napp.get(\"/article\", |content| {\n    let page = context.request.query(\"page\").unwrap_or(\"1\");\n    let per_page = context.request.query(\"per_page\").unwrap_or(\"10\");\n});\n```\n\n### Bind Json\n\n```toml\nserde_derive = \"1.0\"\n\n[dependencies.serde_json]\nversion = \"1.0\"\nfeatures = [\"preserve_order\"]\n```\n\n```rust\n#[macro_use]\nextern crate serde_derive;\nextern crate serde_json;\n```\n\n```rust\napp.post(\"/article\", |content| {\n\n    #[derive(Deserialize, Debug)]\n    struct New {\n        title: String,\n        image: Vec\u003cString\u003e,\n        content: String\n    }\n\n    let new_json = context.request.bind_json::\u003cNew\u003e().unwrap();\n\n    // some code\n\n    let return_json = json!({\n        \"article_id\": 123\n    });\n\n    context.response.from_json(return_json).unwrap();\n});\n```\n\n### Get and set headers, http status code\n\n```rust\napp.get(\"/\", |context| {\n    let token = context.request.header(\"Token\").unwrap_or(\"none\".to_owned());\n\n    context.response.from_text(\"Hello world!\").status_code(200).header((\"Hello\", \"World\")).unwrap();\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanclive%2Fsincere","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanclive%2Fsincere","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanclive%2Fsincere/lists"}