Crates.io | roy |
lib.rs | roy |
version | 0.1.4 |
source | src |
created_at | 2020-10-13 21:51:11.048246 |
updated_at | 2021-03-23 21:58:13.496379 |
description | This crate is a high-level library for consuming RESTful APIs. |
homepage | https://crates.io/crates/roy |
repository | https://github.com/jaredforth/roy |
max_upload_size | |
id | 299389 |
size | 28,881 |
A high-level library for consuming RESTful APIs.
Add this to your Cargo.toml
:
[dependencies]
roy = "0.1"
To use any of the methods on the roy::Client
struct, it has to be instantiated as follows:
// import into scope
use roy::Client;
// Instantiate `Client` with your API's base URL
let c = roy::Client::new("https://httpbin.org".to_string());
All of the examples below assume that the struct has already been instantiated.
roy
provides a high-level request
function that can be used to quickly make requests. To make a
c.get("/get", false); // Make a GET request to your endpoint
or
c.request("/get", roy::RequestMethod::GET, None); // Make GET request using alternate `request` function
c.post("/post", "{some: data}"); // Make a POST request to your endpoint
or
c.request("/post", roy::RequestMethod::POST, Some("{}")); // Make POST request using alternate `request` function
c.patch("/patch", "{some: data}"); // Make a PATCH request to your endpoint
or
c.request("/patch", roy::RequestMethod::PATCH, Some("{}")); // Make PATCH request using alternate `request` function
c.put("/put", "{some: data}"); // Make a PUT request to your endpoint
or
c.request("/put", roy::RequestMethod::PUT, Some("{}")); // Make PUT request using alternate `request` function
c.delete("/delete"); // Make a DELETE request to your endpoint
or
c.request("/delete", roy::RequestMethod::DELETE, None); // Make DELETE request using alternate `request` function
Roy is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.
This crate is named after Roy Fielding, who defined Representational State Transfer. According to Wikipedia:
Roy Fielding defined REST in his 2000 PhD dissertation "Architectural Styles and the Design of Network-based Software Architectures" at UC Irvine. He developed the REST architectural style in parallel with HTTP 1.1 of 1996–1999, based on the existing design of HTTP 1.0 of 1996.