Crate graph_rs_sdk

source ·
Expand description

§Microsoft Graph API Client in Rust

graph-rs-sdk is an API client for Microsoft Graph V1.0 and Graph Beta.

Installation and basic usage can be found below and there are extensive examples in the example’s directory on GitHub.

§What APIs are available

The APIs available are generated from Microsoft’s msgraph-metadata repository which stores OpenApi configs for the Graph API. There may be some requests and/or API not yet included in this project but in general most of them are implemented.

For any APIs missing you can make a feature request on GitHub or you can create a PR to add the APIs. Contributions welcome.

§Feature requests or Bug reports.

For bug reports please file an issue on GitHub and a response or fix will be given as soon as possible.

The Discussions tab on GitHub is enabled so feel free to stop by there with any questions or feature requests as well. For bugs, please file an issue first. Other than that feel free to ask questions, provide tips to others, and talk about the project in general.

§Use

use graph_rs_sdk::*;

#[tokio::main]
async fn main() -> GraphResult<()> {
    let client =  Graph::new("ACCESS_TOKEN");

    let response = client.users()
        .list_user()
        .send()
        .await?;

    println!("{response:#?}");

    let body: serde_json::Value = response.json().await?;
    println!("{body:#?}");

    Ok(())
}

§Using the blocking client

The blocking client can be used by calling into_blocking() on a request.

use graph_rs_sdk::*;

fn main() -> GraphResult<()> {
    let client =  Graph::new("ACCESS_TOKEN");

    let response = client.users()
        .list_user()
        .into_blocking()
        .send()?;

    println!("{response:#?}");

    let body: serde_json::Value = response.json()?;
    println!("{body:#?}");

    Ok(())
}

§Use the Graph version one or beta Api

v1() refers to the endpoint for version 1 of the Microsoft graph API. You can also use the beta() method which uses the Microsoft graph beta API endpoint or use custom_endpoint() for those graph APIs that have custom endpoints such as in countries or governments with their own endpoint.

The Graph client must be mutable in order to change from v1 to beta or a custom endpoint.

§Beta
use graph_rs_sdk::*;

#[tokio::main]
async fn main() -> GraphResult<()> {
    let mut client =  Graph::new("ACCESS_TOKEN");

    let response = client.beta()
        .users()
        .list_user()
        .send()
        .await?;

    println!("{response:#?}");

    let body: serde_json::Value = response.json().await?;
    println!("{body:#?}");

    Ok(())
}
§Custom Endpoint
use graph_rs_sdk::*;

#[tokio::main]
async fn main() -> GraphResult<()> {
    let mut client =  Graph::new("ACCESS_TOKEN");

    let response = client.custom_endpoint("https://api.microsoft.com/api")
        .users()
        .list_user()
        .send()
        .await?;

    println!("{response:#?}");

    let body: serde_json::Value = response.json().await?;
    println!("{body:#?}");

    Ok(())
}
§Custom endpoint using use_endpoint()
use graph_rs_sdk::*;

#[tokio::main]
async fn main() -> GraphResult<()> {
    let mut client =  Graph::new("ACCESS_TOKEN");
    client.use_endpoint("https://graph.microsoft.com");

    let response = client
        .users()
        .list_user()
        .send()
        .await?;

    println!("{response:#?}");

    let body: serde_json::Value = response.json().await?;
    println!("{body:#?}");

    Ok(())
}
  • For more information and examples please see the repository on GitHub
  • If you run into issues related to graph-rs-sdk specifically please file an issue on GitHub

§OAuth

OAuth client implementing the OAuth 2.0 and OpenID Connect protocols on Microsoft identity platform

Purpose built as OAuth client for Microsoft Graph and the graph-rs-sdk project. This project can however be used outside graph-rs-sdk as an OAuth client for Microsoft Identity Platform.

§Supported Authorization Flows

Modules§

Structs§

Enums§

Statics§

Traits§

Type Aliases§