{"id":16567457,"url":"https://github.com/volllly/restcrab","last_synced_at":"2025-03-16T20:31:00.044Z","repository":{"id":45645332,"uuid":"397940271","full_name":"volllly/restcrab","owner":"volllly","description":"Procedural macro to automatically generate a REST client from a trait definition.","archived":false,"fork":false,"pushed_at":"2025-02-16T18:58:50.000Z","size":99,"stargazers_count":3,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-27T13:17:59.015Z","etag":null,"topics":["macros","rest","restclient","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/restcrab/","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/volllly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-19T12:45:35.000Z","updated_at":"2024-04-09T09:23:38.000Z","dependencies_parsed_at":"2023-11-30T11:24:44.557Z","dependency_job_id":"24620302-c4e1-47ca-ab30-2e2cd372f112","html_url":"https://github.com/volllly/restcrab","commit_stats":{"total_commits":55,"total_committers":4,"mean_commits":13.75,"dds":0.4545454545454546,"last_synced_commit":"e05760b7c2eca5dd08920b9e15d2dc58141dc020"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volllly%2Frestcrab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volllly%2Frestcrab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volllly%2Frestcrab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volllly%2Frestcrab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/volllly","download_url":"https://codeload.github.com/volllly/restcrab/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830912,"owners_count":20354848,"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":["macros","rest","restclient","rust"],"created_at":"2024-10-11T21:06:37.585Z","updated_at":"2025-03-16T20:30:59.752Z","avatar_url":"https://github.com/volllly.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Restcrab\n[![crates.io](https://img.shields.io/crates/v/restcrab)](https://crates.io/crates/restcrab)\n[![docs.rs](https://docs.rs/restcrab/badge.svg)](https://docs.rs/restcrab/)\n\nRestcrab provides a procedural macro [`restcrab`](crate::restcrab) and a trait [`Restcrab`](crate::Restcrab) for generating a REST client from a trait definition.\n\n## Usage\n\n```rust no_run\nuse std::collections::HashMap;\n\nuse serde::{Serialize, Deserialize};\nuse restcrab::{restcrab, Restcrab, crabs::reqwest};\n\n#[derive(Serialize, Deserialize)]\nstruct Request {\n  id: i32\n}\n\n#[derive(Serialize, Deserialize)]\nstruct Response {\n  message: String\n}\n\n#[restcrab(crab = \"reqwest::Reqwest\")]\ntrait Service {\n  #[restcrab(method = \"GET\", uri = \"/empty\")]\n  fn uri_from_attribute();\n\n  #[restcrab(method = \"GET\", uri = \"/empty/{name}\")]\n  fn uri_with_parameter(#[parameter] name: \u0026str);\n\n  #[restcrab(method = \"GET\")]\n  fn uri_from_method_name();\n\n  #[restcrab(method = \"GET\", uri = \"/static_header\", header(\"Content-Type\", \"application/json\"))]\n  fn static_header();\n\n  #[restcrab(method = \"GET\", uri = \"/static_headers\", header(\"Content-Type\", \"application/json\"), header(\"User-Agen\", \"Restcrab\"))]\n  fn static_headers();\n\n  #[restcrab(method = \"GET\", uri = \"/static_query\", query(\"some\", \"query\"), query(\"another\", \"one\"))]\n  fn static_queries();\n\n  #[restcrab(method = \"POST\", uri = \"/static_body\", body = \"0\")]\n  fn static_body() -\u003e String;\n\n  #[restcrab(method = \"POST\", uri = \"/dynamic_headers\")]\n  fn dynamic_headers(#[headers] headers: HashMap\u003cString, String\u003e) -\u003e String;\n\n  #[restcrab(method = \"POST\", uri = \"/dynamic_queries\")]\n  fn dynamic_queries(#[queries] queries: HashMap\u003cString, String\u003e) -\u003e String;\n\n  #[restcrab(method = \"POST\", uri = \"/dynamic_headers\", header(\"Content-Type\", \"application/json\"))]\n  fn both_headers(#[headers] headers: HashMap\u003cString, String\u003e) -\u003e String;\n\n  #[restcrab(method = \"POST\", uri = \"/dynamic_body\")]\n  fn dynamic_body(#[body] body: Request) -\u003e Response;\n}\n\nfn main() {\n  let client = ServiceClient::from_options(reqwest::Options {\n    base_url: \"https://service.url\".parse().unwrap()\n  }).unwrap(); \n\n  let mut headers = HashMap::new();\n  headers.insert(\"User-Agent\".to_string(), \"Restcrab\".to_string());\n\n  let mut queries = HashMap::new();\n  queries.insert(\"key\".to_string(), \"value\".to_string());\n\n  let uri_from_attribute:   ()        = client.uri_from_attribute().unwrap();\n  let uri_from_method_name: ()        = client.uri_from_method_name().unwrap();\n  let uri_with_parameter:   ()        = client.uri_with_parameter(\"value\").unwrap();\n  let static_header:        ()        = client.static_header().unwrap();\n  let static_headers:       ()        = client.static_headers().unwrap();\n  let static_queries:       ()        = client.static_queries().unwrap();\n  let static_body:          String    = client.static_body().unwrap();\n  let dynamic_headers:      String    = client.dynamic_headers(headers.clone()).unwrap();\n  let dynamic_queries:      String    = client.dynamic_queries(queries).unwrap();\n  let both_headers:         String    = client.both_headers(headers).unwrap();\n  let dynamic_body:         Response  = client.dynamic_body(Request { id: 0 }).unwrap();\n}\n```\n\n## Modular Backends (crabs)\n\nBecause I like to use unhelpful terminology a backend for restcrab is called a crab.\n\nTypes which implement the [`Restcrab`](crate::Restcrab) trait can be used as crabs.\n\nThe crate provides one crab which uses the [Reqwest](https://docs.rs/reqwest) http client.\n\nIf you want to implement your own crab please look at the [provided implementation](crate::crabs::reqwest) as starting off point \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvolllly%2Frestcrab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvolllly%2Frestcrab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvolllly%2Frestcrab/lists"}