Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jwilm/json-request
library for testing JSON APIs in rust
https://github.com/jwilm/json-request
Last synced: 22 days ago
JSON representation
library for testing JSON APIs in rust
- Host: GitHub
- URL: https://github.com/jwilm/json-request
- Owner: jwilm
- Created: 2015-11-10T15:45:13.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-14T01:10:58.000Z (almost 9 years ago)
- Last Synced: 2024-10-05T01:27:17.149Z (about 1 month ago)
- Language: Rust
- Size: 0 Bytes
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
json-request
============Rust library for talking to JSON HTTP servers
[Documentation][]
## Usage
One method, `request`, is exposed which makes HTTP requests and provides
automatic serialization/deserialization of Rust types to JSON.```rust
extern crate rustc_serialize;
extern crate json_request;use json_request::{request, Method};
#[derive(Debug, RustcEncodable)]
struct RequestData {
ping: bool
}#[derive(Debug, RustcDecodable)]
struct ResponseData {
pong: bool
}// `data` is the object to be serialized and sent to the HTTP server
let data = RequestData { ping: true };// Actually build the request
let res = request(Method::Post, "http://example.com/", Some(data));// Request returns a Result>; hence, two unwrap calls. The wrapped
// value has been deserialized from a JSON response.
let pong: ResponseData = res.unwrap().unwrap();
```## Install
Add the following to your Cargo.toml
```toml
[dependencies.json-request]
git = "https://github.com/jwilm/json-request"
```## Notes
- *TODO*: The `data` parameter should be url encoded and appended to the URL for
GET requests.
- *TODO*: Would be nice to have a DSL macro that's a little more user friendly[Documentation]: http://jwilm.github.io/json-request/json_request