{"id":20269904,"url":"https://github.com/teliosdev/under","last_synced_at":"2025-04-11T04:01:48.293Z","repository":{"id":57671056,"uuid":"303490203","full_name":"teliosdev/under","owner":"teliosdev","description":"A simple rust HTTP server library.","archived":false,"fork":false,"pushed_at":"2023-04-21T04:32:07.000Z","size":129,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-17T14:45:43.533Z","etag":null,"topics":["http-server","rust"],"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/teliosdev.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,"governance":null}},"created_at":"2020-10-12T19:16:17.000Z","updated_at":"2023-08-23T15:59:50.000Z","dependencies_parsed_at":"2023-07-13T19:33:55.666Z","dependency_job_id":null,"html_url":"https://github.com/teliosdev/under","commit_stats":null,"previous_names":["medcat/under"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teliosdev%2Funder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teliosdev%2Funder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teliosdev%2Funder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teliosdev%2Funder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teliosdev","download_url":"https://codeload.github.com/teliosdev/under/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339256,"owners_count":21087214,"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":["http-server","rust"],"created_at":"2024-11-14T12:27:58.002Z","updated_at":"2025-04-11T04:01:48.264Z","avatar_url":"https://github.com/teliosdev.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Under\n\n[![Version](https://img.shields.io/crates/v/under)](https://crates.io/crates/under)\n[![docs.rs](https://img.shields.io/docsrs/under)](https://docs.rs/under)\n[![License](https://img.shields.io/crates/l/under)](./LICENSE)\n[![CI](https://github.com/medcat/under/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/medcat/under/actions/workflows/main.yml)\n\nA very simple HTTP server framework.  This serves as a small layer\nbetween your application code and Hyper.\n\nRight now, this layer is very bare-bones - however, the intent is to\nadd on to this whenever patterns with the code become obvious.  If\nyou encounter any, feel free to create an issue.\n\n## Setting Up\n\nThe simplest way to set up a server is by using `under::Router`:\n\n```rust\nlet mut http = under::http();\nhttp.at(\"/\").get(under::endpoints::simple(under::Response::empty_204));\nhttp.listen(\"localhost:8080\").await.unwrap();\n```\n\nThis will cause the application to run an HTTP server on port 8080\nlocally; running `GET /` would return `204 No Content`.\n\nThe router accepts all kinds of verbs:\n\n```rust\nhttp.at(\"/users\")\n    .get(users::index)\n    .post(users::create)\n    .at(\"/{id}\")\n        .get(users::show)\n        .put(users::update)\n        .delete(users::delete);\n```\n\nNote the hirearchal structure of the `at` calls - if the latter `at`\nis called underneath an already existing `at`, then the paths are\njoined.  The above example is equiavlent to:\n\n```rust\nhttp.at(\"/users\")\n    .get(users::index)\n    .post(users::create);\nhttp.at(\"/users/{id}\")\n    .get(users::show)\n    .put(users::update)\n    .delete(users::delete);\n```\n\nFor verbs that are not included by default, you may use the `method`\nfunction to declare one:\n\n```rust\nhttp.at(\"/users/{id}\")\n    .method(hyper::Method::from_bytes(b\"SOMETHING\").unwrap(), users::something);\n```\n\nOr, if you want to capture all methods, you can use the `all` function\nto do so:\n\n```rust\nhttp.at(\"/users/{id}\").all(users::all);\n```\n\n## Endpoints\n\nWhen declaring a path, it must route to an endpoint - the argument\npassed into the verb function, e.g. `get(users::show)`.  The value\npassed _must_ implement `under::Endpoint`.  `under::Endpoint` is implemented for\n`fn(under::Request) -\u003e impl Future\u003cOutput = Result\u003cunder::Response, anyhow::Error\u003e + Send + Sync + 'static`;\nso, declaring an endpoint can be as simple as:\n\n```rust\nasync fn index(request: under::Request) -\u003e Result\u003cunder::Response, anyhow::Error\u003e {\n    todo!()\n}\n```\n\nand used as above.  This library also comes with a few built-in\nendpoints in `under::endpoints`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteliosdev%2Funder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteliosdev%2Funder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteliosdev%2Funder/lists"}