Jplaceholder

Build Status

A Rust library for the JSON Placeholder API

Table of Contents

Example:

```rust extern crate jplaceholder; use jplaceholder::Model; use jplaceholder::Post;

match Post::find(2) { Some(post) => println!("Title of the article {}: {}", post.id, post.title), None => println!("Article not found!") } ```

Installation

To install the library, you just have to put it into your Cargo.toml file: toml jplaceholder = "0.1.0" Then, require the library into your main file. rust extern crate jplaceholder;

Usage

The model trait

The model trait provides usefull methods to interact with the resources.

fn find(id: i32) -> Option;

Finds a resource by its ID

Example: ```rust use jplaceholder::Model; use jplaceholder::Post;

match Post::find(2) { Some(post) => println!("Title of the article {}: {}", post.id, post.title), None => println!("Article not found!") } ```

fn all(id: i32) -> Option;

Gets all of the resources

Example: ```rust use jplaceholder::Model; use jplaceholder::Post;

let posts: Vec = Post::all(); for post in posts { println!("The title of the post {} is: {}", post.id, post.title) } ```

fn create() -> Vec;

Creates a new resource

Example: ```rust use jplaceholder::Model; use jplaceholder::Post;

let post = Post{id: 5, title: String::from("Hey"), body: String::from("hehe"), user_id: 5};

println!("The title of the post {} is: {}", post.id, post.title) ```

Contribution guide

  1. Fork and Clone the repository
  2. Create your own branch
  3. Start Coding!
  4. Make a pull request when you're done :)