Jplaceholder
A Rust library for the JSON Placeholder API Documentation: https://docs.rs/jplaceholder/1.0.1/jplaceholder/
Table of Contents
Example:
extern crate jplaceholder;
use Model;
use Post;
match find
Installation
To install the library, you just have to put it into your Cargo.toml file:
= "1.0.1"
Then, require the library into your main file.
extern crate jplaceholder;
Usage
The model trait
The model trait provides usefull methods to interact with the resources.
Implementations
- Post
- User
fn find(id: i32) -> Option;
Finds a resource by its ID
Example:
use Model;
use Post;
match find
fn all(id: i32) -> Option;
Gets all of the resources
Example:
use Model;
use Post;
let posts: = all;
for post in posts
fn create() -> Vec;
Creates a new resource
Example:
use Model;
use Post;
let post = Post;
create;
Relationships
Relationships let you interact between models. Let's say that I get the first user like this:
use Model;
use User;
use Post;
let user = match find ;
Now, if I want to get all of the articles posted by this user:
// .......
let posts: = user.posts.expect;
println!;
And conversely, if I want to get the user that posted an article:
use Model;
use Post;
if let Some = find
Contribution guide
- Fork and Clone the repository
- Create your own branch
- Start Coding!
- Make a pull request when you're done :)