All Projects → abonander → Anterofit

abonander / Anterofit

Licence: other
Strongly typed, asynchronous REST client framework for Rust.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Anterofit

Simple Web Server
A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
Stars: ✭ 2,261 (+1708.8%)
Mutual labels:  rest, client
Fakerest
Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
Stars: ✭ 350 (+180%)
Mutual labels:  rest, client
Jenkins Rest
Java client, built on top of jclouds, for working with Jenkins REST API
Stars: ✭ 201 (+60.8%)
Mutual labels:  rest, client
Bee
A framework for IOTA nodes, clients and applications in Rust
Stars: ✭ 176 (+40.8%)
Mutual labels:  crates, client
Httpotion
(soft-deprecated) HTTP client for Elixir (use Tesla please)
Stars: ✭ 723 (+478.4%)
Mutual labels:  rest, client
Pysnow
Python library for the ServiceNow REST API
Stars: ✭ 162 (+29.6%)
Mutual labels:  rest, client
Httpie
As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/httpie
Stars: ✭ 53,052 (+42341.6%)
Mutual labels:  rest, client
Restrequest4delphi
API to consume REST services written in any programming language with support to Lazarus and Delphi
Stars: ✭ 162 (+29.6%)
Mutual labels:  rest, client
Elasticsearch Js
Official Elasticsearch client library for Node.js
Stars: ✭ 4,828 (+3762.4%)
Mutual labels:  rest, client
Purest
REST API Client Library
Stars: ✭ 448 (+258.4%)
Mutual labels:  rest, client
Verb
Organize and send HTTP requests from Emacs
Stars: ✭ 205 (+64%)
Mutual labels:  rest, client
Flickr Sdk
Almost certainly the best Flickr API client in the world for node and the browser
Stars: ✭ 104 (-16.8%)
Mutual labels:  rest, client
Bitcoin Core
A modern Bitcoin Core REST and RPC client.
Stars: ✭ 379 (+203.2%)
Mutual labels:  rest, client
Swagger Codegen Play Scala
Swagger client generator which is based on the PlayWS library
Stars: ✭ 9 (-92.8%)
Mutual labels:  rest, client
Cloudflare
An asynchronous Ruby wrapper for the CloudFlare V4 API.
Stars: ✭ 113 (-9.6%)
Mutual labels:  rest, client
Narration
The Narration PHP Framework - Empowering everyone to build reliable and loosely coupled web apps.
Stars: ✭ 119 (-4.8%)
Mutual labels:  rest
Jsonapi Vuex
Use a JSONAPI api with a Vuex store, with data restructuring/normalization.
Stars: ✭ 123 (-1.6%)
Mutual labels:  rest
Rest Api Fuzz Testing
REST API Fuzz Testing (RAFT): Source code for self-hosted service developed for Azure, including the API, orchestration engine, and default set of security tools (including MSR's RESTler), that enables developers to embed security tooling into their CI/CD workflows
Stars: ✭ 119 (-4.8%)
Mutual labels:  rest
Vertx Mqtt
Vert.x MQTT
Stars: ✭ 117 (-6.4%)
Mutual labels:  client
Tooty
An alternative multi-accounts Web client for Mastodon.
Stars: ✭ 124 (-0.8%)
Mutual labels:  client

anterofit Build Status On Crates.io

Anterofit is a collection of Rust macros coupled to a lightweight, self-contained HTTP framework that allows you to easily create strongly-typed Rust wrappers for calling REST APIs.

// See examples/post_service.rs for more details
#[macro_use] extern crate anterofit;
#[macro_use] extern crate serde_derive;

use anterofit::{Adapter, Url};

#[derive(Debug, Deserialize)]
struct Post {
    pub userid: Option<u64>,
    pub id: u64,
    pub title: String,
    pub body: String
}

service! {
    trait PostService {
        /// Get a Post by id.
        fn get_post(&self, id: u64) -> Post {
            GET("/posts/{}", id)
        }

        /// Get all posts.
        fn get_posts(&self) -> Vec<Post> {
            GET("/posts")
        }

        /// Create a new Post under the given user ID with the given title and body.
        fn new_post(&self, userid: u64, title: &str, body: &str) -> Post {
            POST("/posts/");
            // We use the `EAGER:` keyword so we can use borrowed values in the body.
            // This serializes the body value immediately instead of waiting to serialize
            // it on the executor.
            body_map!(EAGER:
                "userid" => userid,
                "title": title,
                "body": body
            )
        }
    }
}

fn main() {
    // Navigate to this URL in your browser for details. Very useful test API.
    let url = Url::parse("https://jsonplaceholder.typicode.com").unwrap();

    let adapter = Adapter::builder()
        .base_url(url)
        // When your REST API uses JSON in both requests and responses
        .serialize_json()
        .build();

    create_post(&adapter);
    fetch_posts(&adapter);
}

/// Create a new Post.
// All service traits are implemented for `Adapter` by default; using generics like this promotes good namespacing.
fn create_post<P: PostService>(post_service: &P) {
    let post = post_service.new_post(42, "Hello", "World!")
        // Execute the request in the background and wait for it to complete
        .exec().block()
        .unwrap();

    println!("{:?}", post);
}

/// Fetch the top 3 posts in the database.
// Service traits are object-safe by default
fn fetch_posts(post_service: &PostService) {
    let posts = post_service.get_posts()
        // Shorthand for .exec().block(), but executes the request on the current thread.
        .exec_here()
        .unwrap();

    for post in posts.into_iter().take(3) {
        println!("{:?}", post);
    }
}

Inspired by Square's Retrofit, as referenced in the name, Anterofit is even more strongly typed as everything that is feasible to check at compile-time, is. Runtime errors are, with few exceptions, reserved for error conditions that can only be discovered at runtime.

Usage

Get started with our User Guide

Or an in-depth look with our Documentation

Setup

Serde and JSON serialization:

Enabled by default with the serde-all feature.

Cargo.toml:

[dependencies]
anterofit = "0.1"
# `serde` is required in the dependencies but not in the crate root.
serde = "0.9"
serde_derive = "0.9"

Crate Root:

#[macro_use] extern crate anterofit;
#[macro_use] extern crate serde_derive;

rustc-serialize:

Cargo.toml:

[dependencies]
rustc-serialize = "0.3"

[dependencies.anterofit]
version = "0.1"
default-features = false
features = ["rustc-serialize"]

Crate Root:

#[macro_use] extern crate anterofit;
extern crate rustc_serialize;

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].