{"id":26245592,"url":"https://github.com/askonomm/bobby","last_synced_at":"2025-07-03T22:33:34.055Z","repository":{"id":280164627,"uuid":"941182843","full_name":"askonomm/bobby","owner":"askonomm","description":"A minimal web framework for Rust.","archived":false,"fork":false,"pushed_at":"2025-03-03T20:29:58.000Z","size":20,"stargazers_count":2,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-28T20:04:10.609Z","etag":null,"topics":["api","http","rest","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/askonomm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-01T17:28:11.000Z","updated_at":"2025-03-02T17:48:01.000Z","dependencies_parsed_at":"2025-03-01T17:37:24.717Z","dependency_job_id":"c28bf5d9-df8c-4167-82ee-c10882aed8c5","html_url":"https://github.com/askonomm/bobby","commit_stats":null,"previous_names":["askonomm/bobby"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/askonomm/bobby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askonomm%2Fbobby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askonomm%2Fbobby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askonomm%2Fbobby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askonomm%2Fbobby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/askonomm","download_url":"https://codeload.github.com/askonomm/bobby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/askonomm%2Fbobby/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263250271,"owners_count":23437264,"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":["api","http","rest","web-framework"],"created_at":"2025-03-13T12:37:10.566Z","updated_at":"2025-07-03T22:33:33.975Z","avatar_url":"https://github.com/askonomm.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bobby\n\nA minimal web framework for Rust.\n\n**Note:** very much pre-alpha.\n\n## Installation\n\nAdd Bobby to your `Cargo.toml`:\n\n```toml\n[dependencies]\nbobby = \"0.1.2\"\n```\n\n## Usage\n\nBasic usage looks like this:\n\n```rust\nuse bobby::{Bobby, Response};\n\n// Create app\nlet mut app = Bobby::new();\n\n// Config address\napp.with_address([127, 0, 0, 1], 3333);\n\n// Routes\napp.get(\"/\", |_| Response::html(\"Hello, \u003cstrong\u003eWorld\u003c/strong\u003e\"));\napp.get(\"/some/{thing?}\", |_| Response::html(\"An optional route part.\"));\napp.get(\"/other/{thing}\", |_| Response::html(\"A non-optional route part.\"));\n\n// Run\napp.run();\n```\n\n### App configuration\n\nBobby can be configured using `with_` methods.\n\n#### Address and port\n\nTo have Bobby listen on a given address and port, use the `with_address` method:\n\n```rust\napp.with_address([127, 0, 0, 1], 3333);\n```\n\nIf you don't configure this then Bobby will listen on address `127.0.0.1` and port `8080` by default.\n\n#### Logging\n\nBobby has built-in support for logging with the [log](https://crates.io/crates/log) interface, so you could use any logging library that supports it to generate logs.\n\nAn example with using the [env_logger](https://crates.io/crates/env_logger) library:\n\n```rust\nlet mut logger = env_logger::Builder::from_default_env();\nlogger.target(env_logger::Target::Stdout);\nlogger.init();\n\nlet mut app = Bobby::new();\n\n// and so forth ...\n```\n\nWould then generate the following output in your `stdout`:\n\n```stdout\n[2025-03-02T14:05:51Z INFO  bobby::bobby] Listening on 127.0.0.1:3112 ...\n[2025-03-02T14:05:56Z INFO  bobby::bobby] HTTP/1.1 GET /\n[2025-03-02T14:05:57Z INFO  bobby::bobby] HTTP/1.1 GET /\n[2025-03-02T14:05:57Z INFO  bobby::bobby] HTTP/1.1 GET /\n[2025-03-02T14:06:01Z INFO  bobby::bobby] HTTP/1.1 GET /asd\n[2025-03-02T14:06:01Z WARN  bobby::bobby] HTTP/1.1 GET /asd - Not found\n```\n\n### Routing\n\nRoutes are added to the instance of `Bobby` by calling route related methods. An example route looks like this:\n\n```rust\napp.get(\"/\", |req| {\n  Response::html(\"Hello, World.\")\n});\n```\n\nSupported methods are:\n\n- `get`\n- `post`\n- `put`\n- `delete`\n- `patch`\n- `options`\n- `head`\n\n### Requests\n\nEach route function gets a `Request` instance passed to it as its single argument. \n\n#### Method\n\nYou can see the incoming request' method:\n\n```rust\napp.get(\"/\", |req| {\n  let method = req.method();\n});\n```\n\n#### URI\n\nYou can see the incoming request' URI:\n\n```rust\napp.get(\"/\", |req| {\n  let uri = req.uri();\n});\n```\n\n#### Parameters\n\nYou can get the route parameters:\n\n```rust\napp.get(\"/hello/{who}\", |req| {\n  let who = req.param(\"who\");\n});\n```\n\n### Responses\n\nEach route must return an instance of `Response`.\n\n#### Response: `HTML`\n\nYou can return a HTML response:\n\n```rust\napp.get(\"/\", |req| {\n  Response::html(\"Hello, World.\")\n});\n```\n\n#### Response: `JSON`\n\nYou can return a JSON response:\n\n```rust\nuse serde_json::json;\n\napp.get(\"/\", |req| {\n  Response::json(json!({\n    \"name\": \"John\"\n  }))\n});\n```\n\n#### Setting headers\n\nYou can set the response headers:\n\n```rust\napp.get(\"/\", |req| {\n  Response::html(\"Hello, World.\")\n    .with_header(\"Content-Type\", \"text/html\")\n});\n```\n\n#### Setting status code\n\nYou can set the response status:\n\n```rust\napp.get(\"/\", |req| {\n  Response::html(\"Not found.\")\n    .with_header(\"Content-Type\", \"text/html\")\n    .with_status(404)\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faskonomm%2Fbobby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faskonomm%2Fbobby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faskonomm%2Fbobby/lists"}