sanity

Crates.iosanity
lib.rssanity
version0.1.1
sourcesrc
created_at2019-11-25 20:32:09.939851
updated_at2019-11-25 21:34:51.059461
descriptionThe open source client for consuming https://sanity.io with Rust, based on reqwest.
homepage
repositoryhttps://github.com/DukeFerdinand/sanity.rs
max_upload_size
id184284
size8,201
Douglass Hooker (DukeFerdinand)

documentation

README

Sanity RS

The open source client for consuming https://sanity.io with Rust, based on reqwest.

The goal behind this project is to provide a relatively low level wrapper for consuming Sanity-powered APIs. The first goal is to make sure all bases are covered for running bare GROQ query strings, then I'd like to add in support for some sort of ORM to run queries against (If you know any easy way to implement this please let me know).

Stretch goal would be adding a higher level GraphQL consumer to make Sanity operations a breeze, but there are other GraphQL projects for Rust so that's not a high priority :)

This project is in alpha, so very limited features are available.

Getting started

Add the sanity crate to you dependencies:

[dependencies]
sanity = "0.1.0"

Or directly via github:

[dependencies]
sanity = { git = "https://github.com/DukeFerdinand/sanity.rs" }

Then include as you would any other external crate:

// main.rs or wherever

...
extern crate sanity;
...

fn main {
  ...
}

Usage

As of right now (v0.1.0), only get requests are supported.

GET request

extern crate sanity;
use sanity::helpers::get_json;

fn main() {
  // Ideally you would pull these values from an env of some sort
  // PLEASE do not use bare strings in your project
  let mut sn = sanity::create(
    "proj_id",                // Sanity project ID to use
    "data_set",               // Data set to query. i.e. "development"
    "Long_string_for_token",  // Bearer token
    false,                    // Use prod cdn or not
  );
  let res = sn.get(&String::from("*[_type == 'recipe']"));
  if res.is_ok() {
    println!("{:?}", get_json(res.unwrap()));
  }
}

Contributing

I'm admittedly pretty new to Rust, so if you see anything you'd like to change or anything you'd like to see added, please open a feature request in the github issues :)

I'm open to accepting any and all PRs as long as they fit the project and contain good code!

Commit count: 12

cargo fmt