{"id":16795187,"url":"https://github.com/abonander/anterofit","last_synced_at":"2025-04-07T12:08:42.962Z","repository":{"id":57489834,"uuid":"69615528","full_name":"abonander/anterofit","owner":"abonander","description":"Strongly typed, asynchronous REST client framework for Rust.","archived":false,"fork":false,"pushed_at":"2020-07-13T22:37:20.000Z","size":295,"stargazers_count":136,"open_issues_count":12,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T11:02:40.934Z","etag":null,"topics":["client","crates","rest"],"latest_commit_sha":null,"homepage":"","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/abonander.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2016-09-29T23:18:22.000Z","updated_at":"2025-02-08T22:56:10.000Z","dependencies_parsed_at":"2022-08-29T19:31:31.008Z","dependency_job_id":null,"html_url":"https://github.com/abonander/anterofit","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/abonander%2Fanterofit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abonander%2Fanterofit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abonander%2Fanterofit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abonander%2Fanterofit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abonander","download_url":"https://codeload.github.com/abonander/anterofit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648978,"owners_count":20972945,"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":["client","crates","rest"],"created_at":"2024-10-13T09:15:38.723Z","updated_at":"2025-04-07T12:08:42.947Z","avatar_url":"https://github.com/abonander.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# anterofit [![Build Status](https://travis-ci.org/abonander/anterofit.svg?branch=master)](https://travis-ci.org/abonander/anterofit) [![On Crates.io](https://img.shields.io/crates/v/anterofit.svg)](https://crates.io/crates/anterofit)\n\nAnterofit is a collection of Rust macros coupled to a lightweight, self-contained HTTP framework that\nallows you to easily create strongly-typed Rust wrappers for calling REST APIs.\n\n```rust\n// See examples/post_service.rs for more details\n#[macro_use] extern crate anterofit;\n#[macro_use] extern crate serde_derive;\n\nuse anterofit::{Adapter, Url};\n\n#[derive(Debug, Deserialize)]\nstruct Post {\n    pub userid: Option\u003cu64\u003e,\n    pub id: u64,\n    pub title: String,\n    pub body: String\n}\n\nservice! {\n    trait PostService {\n        /// Get a Post by id.\n        fn get_post(\u0026self, id: u64) -\u003e Post {\n            GET(\"/posts/{}\", id)\n        }\n\n        /// Get all posts.\n        fn get_posts(\u0026self) -\u003e Vec\u003cPost\u003e {\n            GET(\"/posts\")\n        }\n\n        /// Create a new Post under the given user ID with the given title and body.\n        fn new_post(\u0026self, userid: u64, title: \u0026str, body: \u0026str) -\u003e Post {\n            POST(\"/posts/\");\n            // We use the `EAGER:` keyword so we can use borrowed values in the body.\n            // This serializes the body value immediately instead of waiting to serialize\n            // it on the executor.\n            body_map!(EAGER:\n                \"userid\" =\u003e userid,\n                \"title\": title,\n                \"body\": body\n            )\n        }\n    }\n}\n\nfn main() {\n    // Navigate to this URL in your browser for details. Very useful test API.\n    let url = Url::parse(\"https://jsonplaceholder.typicode.com\").unwrap();\n\n    let adapter = Adapter::builder()\n        .base_url(url)\n        // When your REST API uses JSON in both requests and responses\n        .serialize_json()\n        .build();\n\n    create_post(\u0026adapter);\n    fetch_posts(\u0026adapter);\n}\n\n/// Create a new Post.\n// All service traits are implemented for `Adapter` by default; using generics like this promotes good namespacing.\nfn create_post\u003cP: PostService\u003e(post_service: \u0026P) {\n    let post = post_service.new_post(42, \"Hello\", \"World!\")\n        // Execute the request in the background and wait for it to complete\n        .exec().block()\n        .unwrap();\n\n    println!(\"{:?}\", post);\n}\n\n/// Fetch the top 3 posts in the database.\n// Service traits are object-safe by default\nfn fetch_posts(post_service: \u0026PostService) {\n    let posts = post_service.get_posts()\n        // Shorthand for .exec().block(), but executes the request on the current thread.\n        .exec_here()\n        .unwrap();\n\n    for post in posts.into_iter().take(3) {\n        println!(\"{:?}\", post);\n    }\n}\n```\n\nInspired by [Square's Retrofit](https://square.github.io/retrofit), as referenced in the name, Anterofit is even\nmore strongly typed as everything that is feasible to check at compile-time, is. Runtime errors are,\nwith few exceptions, reserved for error conditions that can only be discovered at runtime.\n\nUsage\n-----\n\nGet started with our [User Guide](GUIDE.md)\n\nOr an in-depth look with our [Documentation](https://docs.rs/anterofit)\n\n### Setup\n\n#### [Serde](https://crates.io/crates/serde) and JSON serialization:\n\nEnabled by default with the `serde-all` feature.\n\n`Cargo.toml`:\n```toml\n[dependencies]\nanterofit = \"0.1\"\n# `serde` is required in the dependencies but not in the crate root.\nserde = \"0.9\"\nserde_derive = \"0.9\"\n```\n\nCrate Root:\n```rust\n#[macro_use] extern crate anterofit;\n#[macro_use] extern crate serde_derive;\n```\n\n#### [`rustc-serialize`](https://crates.io/crates/rustc-serialize):\n\n`Cargo.toml`:\n```toml\n[dependencies]\nrustc-serialize = \"0.3\"\n\n[dependencies.anterofit]\nversion = \"0.1\"\ndefault-features = false\nfeatures = [\"rustc-serialize\"]\n```\n\nCrate Root:\n```rust\n#[macro_use] extern crate anterofit;\nextern crate rustc_serialize;\n```\n\nLicense\n-------\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabonander%2Fanterofit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabonander%2Fanterofit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabonander%2Fanterofit/lists"}