Go developers can now access Microsoft Graph with streamlined authentication and more
Microsoft Graph is a single REST API that unifies data across many Microsoft services under one single endpoint. Go developers can now integrate their application with Microsoft Graph via the new Microsoft Graph Go SDK.
Go has a large developer community and was listed as one of the top languages in StackOverFlow’s 2021 survey and previously, Go developers were only able to access Microsoft Graph using HTTP calls. We have heard your feedback over the years for a Microsoft Graph Go SDK and appreciate all your comments. Today, we are pleased to announce that a new Microsoft Graph Go SDK is now available in preview!
Like other Microsoft Graph SDKs, our goal for this SDK is to enable the use of Microsoft Graph APIs on Day 1, providing a fluent style API and models that support retry handling, secure redirects, batching requests, large file management, and many more capabilities.
The Microsoft Graph Go SDK allows you to connect and retrieve data for any of the supported Microsoft services that are available on Microsoft Graph. The preview version includes features to leverage new modern development described below.
The SDK takes advantage of the of the Azure Identity library so developers can use a single API to authenticate against Azure services and Microsoft Graph. The authentication experience provides support for a set of credential types, such as device code flow, client certificate credentials grant flow, and many more authentication scenarios!
Device code flow is ideal for devices that have limited input capabilities like IoT devices, TVs, and wearables. To use this authentication method and query Microsoft Graph with the Go SDK, simply add the following lines to your application.
To use the device code authentication flow and query the user’s drive calling Microsoft Graph with the Go SDK, simply add the following lines to your application.
Secure redirect and retry handlers
Microsoft Graph SDKs use the concept of middleware to provide components designed to help developers overcome different challenges they may have building their applications.
Fluent style API
The Microsoft Graph Go SDK offers a fluent style API to create requests. Fluent style improves the code readability thanks to method chaining and reduces the developers’ learning curve.
Let’s view a set of examples:
Should you prefer to use the native net http client to handcraft your requests, you can always leverage the factories in the Microsoft Graph Go SDK Core and benefit from the retry and redirect handlers.
Companion beta SDK
Microsoft Graph beta client libraries allows developers to target the Microsoft Graph beta endpoint that includes APIs that are currently in preview and aren’t yet generally available.
To try the latest upcoming APIs, use the Microsoft Graph Go Beta SDK by adding the beta SDK to your project as follows:
go get -u github.com/microsoftgraph/msgraph-beta-sdk-go
You can then use both the v1.0 and the beta SDKs in the same project. This approach offers the benefit of only using unstable beta APIs when necessary and relying on stable v1.0 as much as possible.
Getting started with Microsoft Graph Go SDK
To get familiar with the Microsoft Graph SDKs, start with the documentation page.
Start saving time and removing complexity in your code today. Sign up for the Microsoft 365 Developer Program to get a free Microsoft 365 developer instant sandbox and start building Go apps with Microsoft Graph.
See the following instructions to add the new Microsoft Graph Go SDK to your project.
- Open a shell
- Navigate to your project root
- Run the following command to add the Go SDK for Microsoft Graph
go get -u github.com/microsoftgraph/msgraph-sdk-go
- Run the following command to add Azure Identity
go get -u github.com/Azure/azure-sdk-for-go/sdk/azidentity
Here are some resources we have pulled together to help you get started. You will find a list of known limitations, a link to our documentation, and a handy tool.
- Check out this GitHub post to access a detailed list of known limitations. We are working to remove these limitations before the general availability of the SDK.
- Explore our public documentation, which now contains go snippets.
- Use Microsoft Graph Explorer, a tool that lets you make requests and see responses against the Microsoft Graph, and which showcases corresponding snippets to requests you make.
Try out the new version today!