{"id":33933140,"url":"https://github.com/hephex/api","last_synced_at":"2026-04-08T13:31:05.893Z","repository":{"id":57490892,"uuid":"90460907","full_name":"hephex/api","owner":"hephex","description":"api client for Rust","archived":false,"fork":false,"pushed_at":"2017-07-08T20:44:47.000Z","size":9,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-01-02T08:22:39.895Z","etag":null,"topics":["api","client","http"],"latest_commit_sha":null,"homepage":null,"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/hephex.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-05-06T12:19:20.000Z","updated_at":"2021-10-22T14:08:21.000Z","dependencies_parsed_at":"2022-08-29T20:31:29.328Z","dependency_job_id":null,"html_url":"https://github.com/hephex/api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hephex/api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hephex%2Fapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hephex%2Fapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hephex%2Fapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hephex%2Fapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hephex","download_url":"https://codeload.github.com/hephex/api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hephex%2Fapi/sbom","scorecard":{"id":461737,"data":{"date":"2025-08-11","repo":{"name":"github.com/hephex/api","commit":"5174c70168299e772c28ba5805e2839543a287d2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/9 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T11:18:08.708Z","repository_id":57490892,"created_at":"2025-08-19T11:18:08.708Z","updated_at":"2025-08-19T11:18:08.708Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31558379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T10:21:54.569Z","status":"ssl_error","status_checked_at":"2026-04-08T10:21:38.171Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","client","http"],"created_at":"2025-12-12T13:02:40.014Z","updated_at":"2026-04-08T13:31:05.883Z","avatar_url":"https://github.com/hephex.png","language":"Rust","readme":"# api\n\n`api` provides a set of utilities for defining\nHTTP API on the client side without worrying about\nthe actual HTTP client (until you send the\nrequest!).\n\n## Api trait\n\n`api::Api` is a trait used to define a remote API.\nThe developer must implement it for the `struct`\nthat represents the API endpoint.\n\nFor our examples, we'll create a simple client for [httpbin][httpbin]\nand its endpoint `/delay:n` (delays responding n seconds\nand returns some information about the request).\n\n`Api` has three associated types:\n\n+ `Body` is used to generate the request body and\n    it must implement the trait `std::io::Read`.\n   If the endpoint doesn't require a body `std::io::Empty`\n    should be used.\n\n+ `Reply` defines the response that we expect to receive\n    from the API.\n+ `Error` defines all the expected errors that we could get when\n    the response is received.\n\nFirst of all, we need to define the request and the response.\n`/delay/:n` has only one parameter in the path and we'll only care about the fields `origin` and `headers` in the JSON response\n(we'll use `serde_json` to parse the response's body).\n\n```rust\nextern crate api;\n#[macro_use]\nextern crate serde_derive;\nextern crate serde;\nextern crate serde_json;\n\n// request for /delay/:n\nstruct Delay {\n    delay: u8\n}\n\n// it's a subset of the available data\n#[derive(Deserialize)]\nstruct Info {\n    origin: String, // ip address\n    headers: BTreeMap\u003cString, String\u003e, // headers received by the server\n}\n\n\nimpl api::Api for Delay {\n    type Reply = Info;\n    type Body = io::Empty;\n    type Error = serde_json::Error;\n\n    ...\n}\n```\n\nThen, we can start defining how the HTTP request will look like\nimplementing the trait `Api` for `Delay`.\nWe'll send a `GET` request to `/delay/:n` and `:n` will be\nreplaced with the value in `Delay.delay`.\n\n```rust\nimpl api::Api for Delay {\n    type Reply = Info;\n    type Body = io::Empty;\n    type Error = serde_json::Error;\n\n    fn method(\u0026self) -\u003e api::Method {\n        api::Method::Get\n    }\n\n    fn path(\u0026self) -\u003e String {\n        // use a safe joiner to create the path!\n        format!(\"/delay/{}\", self.delay)\n    }\n\n    fn query(\u0026self) -\u003e api::Query {\n        // we'll send any parameter in the query\n        Query::new()\n    }\n\n    fn headers(\u0026self) -\u003e api::Headers {\n        let mut headers = api::Headers::new();\n\n        headers.insert(\"X-Request-ID\".to_string(), vec![\"abcde\".to_string()]);\n\n        headers\n    }\n\n    fn body(\u0026self) -\u003e std::io::Empty {\n       std::io::empty()\n    }\n}\n```\n\nNow, we need to create the reply `Info` from\nthe HTTP response represented by the trait `HttpResponse`.\n\n```rust\nimpl api::Api for Delay {\n    type Reply = Info;\n    type Body = io::Empty;\n    type Error = serde_json::Error;\n\n    ...\n\n    fn parse\u003cR: HttpResponse\u003e(\u0026self, resp: \u0026mut R) -\u003e Result\u003cInfo, serde_json::Error\u003e {\n        serde_json::from_reader(resp.body())\n    }\n}\n```\n\n`api` has a trait `Client` to create an adapter for the actual HTTP client, and it implements it for `hyper::Client`.\n`Client` has a method `send` that accepts the base URL for the API\nand the request.\n\n```rust\nextern crate hyper;\n\nuse api::Client;\n\n...\n\nfn main() {\n    let mut client = hyper::Client::new();\n\n    let resp = client.send(\"http://httpbin.org/\", Delay { delay: 1 });\n\n    println!(\"{:?}\", resp);\n}\n```\n\nThe full code is in `examples/httpbin.rs`\n(run `cargo run --example=httpbin --features=use-hyper`).\n\n[httpbin]: https://httpbin.org/ \"httpbin\"\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhephex%2Fapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhephex%2Fapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhephex%2Fapi/lists"}