{"id":13440224,"url":"https://github.com/Ogeon/rustful","last_synced_at":"2025-03-20T09:32:32.266Z","repository":{"id":14131300,"uuid":"16836673","full_name":"Ogeon/rustful","owner":"Ogeon","description":"[OUTDATED] A light HTTP framework for Rust","archived":true,"fork":false,"pushed_at":"2018-06-09T10:04:02.000Z","size":2485,"stargazers_count":860,"open_issues_count":6,"forks_count":51,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-02-28T10:53:53.005Z","etag":null,"topics":["rest","rust","web-framework"],"latest_commit_sha":null,"homepage":"https://docs.rs/rustful","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ogeon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-14T12:32:26.000Z","updated_at":"2025-01-01T13:31:44.000Z","dependencies_parsed_at":"2022-07-15T15:17:33.943Z","dependency_job_id":null,"html_url":"https://github.com/Ogeon/rustful","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ogeon%2Frustful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ogeon%2Frustful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ogeon%2Frustful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ogeon%2Frustful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ogeon","download_url":"https://codeload.github.com/Ogeon/rustful/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244585918,"owners_count":20476838,"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":["rest","rust","web-framework"],"created_at":"2024-07-31T03:01:20.851Z","updated_at":"2025-03-20T09:32:32.260Z","avatar_url":"https://github.com/Ogeon.png","language":"Rust","funding_links":[],"categories":["Libraries","库 Libraries","Rust","库"],"sub_categories":["Web programming","网络编程 Web programming","网页编程","web编程 Web programming"],"readme":"Rustful\n=======\n\n[![Join the chat at https://gitter.im/Ogeon/rustful](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Ogeon/rustful?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n[![Build Status](https://travis-ci.org/Ogeon/rustful.png?branch=master)](https://travis-ci.org/Ogeon/rustful)\n[![Windows Build status](https://ci.appveyor.com/api/projects/status/6a95paoex0eptbgn/branch/master?svg=true)](https://ci.appveyor.com/project/Ogeon/rustful/branch/master)\n\nA light HTTP framework for Rust, with REST-like features. The main purpose\nof Rustful is to create a simple, modular and non-intrusive foundation for\nHTTP applications. It has a mainly stateless structure, which naturally allows\nit to run both as one single server and as multiple instances in a cluster.\n\nSome of the features are:\n\n* Generic response handlers. Just use a function or implement the Handler trait.\n* Some handy macros reduces the risk for typos and makes life easier.\n* Variables in routes, that can capture parts of the requested path.\n* Pluggable request and response filtering.\n\n[Online documentation](http://ogeon.github.io/docs/rustful/master/rustful/index.html).\n\n# Getting Started\n\n## Cargo.toml Entries\n\nAdd the following lines to your `Cargo.toml` file:\n\n```toml\n[dependencies]\nrustful = \"0.9\"\n```\n\n### Cargo Features\n\nSome parts of Rustful can be toggled using Cargo features:\n\n * `ssl` - Enable SSL, and thereby HTTPS. Enabled by default.\n * `multipart` - Enable parsing of `multipart/form-data` requests. Enabled by default.\n\n### Using SSL\n\nRustful support SSL (HTTPS), but does not provide the actual SSL connection.\nIt's however compatible with anything that's made for the same Hyper version,\nso all you have to do is find the one that suits your needs and plug it into\nthe server:\n\n```rust\nlet server_result = Server {\n    handlers: router,\n    host: 8080.into(),\n    ..Server::default()\n}.run_https(my_ssl_server);\n```\n\n## Write Your Server\n\nHere is a simple example of what a simple project could look like. Visit\n`http://localhost:8080` or `http://localhost:8080/Olivia` (if your name is\nOlivia) to try it.\n\n```rust\n//Include macros to be able to use `insert_routes!`.\n#[macro_use]\nextern crate log;\nextern crate env_logger;\n\nextern crate rustful;\n\nuse std::error::Error;\n\nuse rustful::{Server, Context, Response, DefaultRouter};\n\nfn say_hello(context: Context, response: Response) {\n    //Get the value of the path variable `:person`, from below.\n    let person = match context.variables.get(\"person\") {\n        Some(name) =\u003e name,\n        None =\u003e \"stranger\".into()\n    };\n\n    //Use the name from the path variable to say hello.\n    response.send(format!(\"Hello, {}!\", person));\n}\n\nfn main() {\n    env_logger::init().unwrap();\n\n    //Create a DefaultRouter and fill it with handlers.\n    let mut router = DefaultRouter::\u003cfn(Context, Response)\u003e::new();\n    router.build().many(|mut node| {\n        //Handle requests for root...\n        node.then().on_get(say_hello);\n\n        //...and one level below.\n        //`:person` is a path variable and it will be accessible in the handler.\n        node.path(\":person\").then().on_get(say_hello);\n    });\n\n    //Build and run the server.\n    let server_result = Server {\n        handlers: router,\n\n        //Turn a port number into an IPV4 host address (0.0.0.0:8080 in this case).\n        host: 8080.into(),\n\n        //Use default values for everything else.\n        ..Server::default()\n    }.run();\n\n    match server_result {\n        Ok(_server) =\u003e {},\n        Err(e) =\u003e error!(\"could not start server: {}\", e.description())\n    }\n}\n```\n\n## Contributing\n\nContributions are always welcome, even if it's a small typo fix (or maybe I\nshould say \"especially typo fixes\"). You can fork the project and open a pull\nrequest with your changes, or create an issue if you just want to report or\nrequest something. Are you not sure about how to implement your change? Is it\nstill a work in progress? Don't worry. You can still open a pull request where\nwe can discuss it and do it step by step.\n\nNew features are as welcome as fixes, so pull requests and proposals with\nenhancements are very much appreciated, but please explain your feature and\ngive a good motivation to why it should be included. It makes things much\neasier, both for reviewing the feature and for those who are not as familiar\nwith how things work. You can always open an issue where we can discuss the\nfeature and see if it should be included. Asking is better than assuming!\n\n### Testing\n\nRustful is tested on Linux, using Travis, and on Windows, using AppVeyor and a\npull request will not be approved unless it passes these tests. It is\ntherefore a good idea to run tests locally, before pushing your changes, so here\nis a small list of useful commands:\n\n * `cargo test` - Basic unit, documentation and compile tests.\n * `cargo build --no-default-features` - Check if the most minimal version of Rustful builds.\n * `cargo build --no-default-features --features \"feature1 feature2\"` - Check if Rustful with only `feature1` and `feature2` enabled builds.\n * `cargo run --example example_name` - check if the example `example_name` behaves as expected (see the `example` directory).\n\nTravis and AppVeyor will run the tests with the `strict` feature enabled. This\nturns warnings and missing documentation into compile errors, which may be\nharsh, but it's for the sake of the user. Everything should have a description\nand it's not nice to see warnings from your dependencies when you are\ncompiling your project, right? It's therefore recommend that you run your own\ntests with the `strict` feature enabled before pushing, just to see if you\nmissed something.\n\n### Automatic Feature Testing\n\nUser facing Cargo features are automatically gathered from `Cargo.toml` and\ntested one at the time, using `scripts/test_features.sh`. The lack of public\nand private features forces us to use a special annotation to differ between\ninternal and user facing feature. Here is an simple example snippet of how the\n`Cargo.toml` is expected to look:\n\n```toml\n#...\n\n[features]\ndefault = [\"feature_a\", \"feature_b\"]\nfeature_a = [\"feature_c\"]\nfeature_b = []\n\n#internal\nfeature_c = []\n\n[dependencies.optional_lib]\n#feature\noptional=true\n\n#...\n```\n\nFeatures that are supposed to be available to the user has to be declared\nbefore the `#internal` comment. This will tell the test script that these are\nsupposed to be tested.\n\nDependency libraries can also be features, so we have to annotate these as\nwell. Each dependency that is supposed to work as a user facing feature will\nneed a `#feature` comment somewhere within its declaration. This will only\nwork with features that are declared using the above form, and not the\n`feature_lib = { ... }` form.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOgeon%2Frustful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOgeon%2Frustful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOgeon%2Frustful/lists"}