sanity.rs
1.0.0
基於reqwest開源客戶端,用於用RUST的https://sanity.io消費。
該項目的目標是為食用理智的API提供相對較低的水平包裝紙。第一個目標是確保所有基礎都涵蓋了運行裸露的groq查詢字符串,然後我想補充一些ORM來對抗的詢問(如果您知道任何簡單的實施方法,請告訴我)。
伸展目標是增加更高級別的GraphQl消費者,以使理智操作變得輕而易舉,但是還有其他用於Rust的GraustQl項目,因此這不是高優先級的:)
將sanity板條箱添加到您的依賴項中:
[ dependencies ]
sanity = " 0.1.0 "或直接通過github:
[ dependencies ]
sanity = { git = " https://github.com/DukeFerdinand/sanity.rs " }然後像其他任何外部板條箱一樣包含:
// main.rs or wherever
.. .
extern crate sanity ;
.. .
fn main {
.. .
} 截至目前( v0.1.0 ),僅支持get請求。
GET請求 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 ( ) ) ) ;
}
} 我承認對Rust的新鮮陌生,因此,如果您看到任何要更改的內容或您想添加的內容,請在Github問題中打開功能請求:)
我願意接受所有PR,只要它們適合該項目並包含良好的代碼!