Code Monkey home page Code Monkey logo

sanity.rs's Introduction

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!

sanity.rs's People

Contributors

dukeferdinand avatar incker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.