Microsoft Graph Java SDK is a client library that lets you connect and retrieve data from any of the supported Microsoft services that are available on Microsoft Graph API. In December, we announced the release candidate of the Java SDK v6. Today, we’re excited to announce the general availability of Microsoft Graph Java SDK v6.0. The new version of the client library is generated using Kiota, a new generation of code generators that produces more efficient and easier-to-use libraries. Kiota enables us to provide a consistent and fluent API across different platforms and new features to enhance your development experience.
In this blog post, we share new features and benefits of the Microsoft Graph Java SDK v6 and how you can get started with it. With this new version, you can expect improved performance, reduced memory usage, and a more intuitive and fluent API. Learn how the new Microsoft Graph Java SDK v6 can help you connect to Microsoft Graph API and access data from Microsoft 365 services with less code and more features.
For developers who are already using the Microsoft Graph Java SDK in their projects, upgrading to the new version is easy. We have prepared an upgrade guide to help you update your applications to take advantage of the new features and improvements in the Microsoft Graph Java SDK v6.
You can read the release candidate blog post we publish before to know more about the cool stuff that the new Microsoft Graph Java SDK v6 can do.
What’s new in Microsoft Graph Java SDK v6?
Here are some of the highlights of the new version of the client library:
Fluent API style
You can write code that is clear, concise, and expressive. You can chain methods and properties to build requests and access resources in a consistent way. The fluent API style matches the Microsoft Graph REST API syntax and makes it simple to switch between the SDK and raw HTTP requests.
Better IntelliSense
You can add headers and any query options to customize any request by using the new requestConfiguration modifier. With the new modifier, the accuracy of the IntelliSense in the client library was also improved, so you’ll get to see suggestions only for methods that are actually supported by the underlying API.
Pagination support
You can use the new PageIterator to handle pagination for large collections of data. The Pageiterator simplifies consuming paged collections by enumerating the current page and requesting subsequent pages automatically. You can use it to iterate over all the items in a collection without worrying about the details of pagination.
Specialized objects with OData cast support
You can use OData cast to get specialized objects with all the properties in the response, rather than pulling those out from AdditionalData. This can be useful for scenarios where you need to access specific types of entities, such as members of a group.
Backing store and dirty tracking
You can use these features to update only the properties that have changed, instead of sending the whole entity back to the server. This can save bandwidth and improve performance. You can also unblock scenarios like disabling recurrence on an event or removing a mobile phone from a user by setting a property to null.
Batching with improved performance
You can use the new BatchRequestContentCollection to perform multiple tasks with one batch request. A batch request lets you combine multiple requests into one, which can improve the performance and efficiency of your application by reducing the number of network round trips. You can also specify an optional custom implementation of IResponseHandler as part of the GetResponseById function to handle the individual response as you wish when batching.
How to create a custom Microsoft Graph Java client library
One of the benefits of using Kiota is that you can customize your client library to include only the endpoints and APIs that you care about. This can improve the performance and size of your application by reducing the amount of code and dependencies.
To generate a custom library for Microsoft Graph using Kiota, you can opt for the CLI experience or the Visual Studio Code extension.
Whichever experience you choose, you will be able to search for the Microsoft Graph OpenAPI description, include and exclude the paths you’re interested in and finally generate.
You can also use the resources explorer feature on Graph Explorer to select the endpoints you need and download the metadata file and use it as an input to the CLI command and generate your client.
To take advantage of customized experience, first create a new directory for your project and then run the following command in that particular directory to initialize a Java project:
gradle init --dsl groovy --test-framework junit --type java-application --project-name meclient --package meclient
Before you compile and run the generated API client, edit the “.\app\build.gradle
” to add Kiota and Microsoft Graph Java core dependencies:
https://gist.github.com/baywet/9916fa2ed429e17288b8d396b551bfb8
You can then generate a client library and add it as part of your Java application. For example, one way to generate a custom client library that includes only the /me endpoint and its related entities, after having Kiota CLI installed, is to use the following command:
kiota generate --openapi https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml --language java --output app/src/main/java/meclient/apiclient --class-name GraphBaseServiceClient --namespace-name meclient.apiclient --backing-store --include-path '/me'
Note: Kiota CLI version needs to be 1.11.0 at minimum. If you already have Kiota installed, make sure its up to date by running dotnet tool update --global Microsoft.OpenApi.Kiota
Note 2: Visit Kiota client generation to discover all parameters supported
How to get started with Microsoft Graph Java SDK v6?
To get started with the new version of the client library, you can follow these steps:
- Install the Microsoft Graph Java SDK v6 from Maven Central or GitHub.
- Authenticate your client using one of the supported authentication providers.
- Make requests to the Microsoft Graph API using the fluent API style.
- Handle responses and errors using the provided models and handlers.
You can find more details and code samples in the Microsoft Graph SDK documentation as well as tutorials to guide you through creating a basic application that takes advantage of the new version.
Give us your feedback
We hope you enjoy using the new Microsoft Graph Java SDK v6 and find it useful for your projects. We would love to hear your feedback and suggestions on how we can improve it. You can share your thoughts and issues on the Microsoft Graph Java SDK GitHub repository or on the Microsoft Graph Q&A.
Thank you for your support and happy coding!
Follow us on X (Twitter) / @Microsoft365Dev and subscribe to our YouTube channel to stay up to date on the latest developer news and announcements.
0 comments