Sequencing batched requests to Microsoft Graph

So we looked at making parallel requests towards Microsoft Graph by utilising JSON batching in my last blog post, but there’s something we need to talk about further… In this blog post we’ll take batched requests a bit further and we’ll look at using… READ MORE [https://lewisdoes.dev/blog/sequen
multicolored numbers for counting on wooden table
Photo by Keira Burton on Pexels.com
In: Low Code Lewis Content 🚀

So we looked at making parallel requests towards Microsoft Graph by utilising JSON batching in my last blog post, but there’s something we need to talk about further…

In this blog post we’ll take batched requests a bit further and we’ll look at using the dependsOn property to sequence requests. This means we can still batch multiple requests together but we can have them be performed in a specific order, say for example if a certain request is dependent on another having already been executed.

Enjoying my content?

Are you enjoying my content on all things Low Code, and Microsoft Cloud? 😄🙋‍♂️

If you are, make sure you’re subscribed to my blog, to get my content delivered directly to your inbox!

Subscribe

dependsOn

So to implement sequencing in a batched request towards Graph we will need to use the dependsOn property. This property will sit within the nested objects (requests) that we want to make, within our wider array called requests.

Within each request we will add the dependsOn property which will accept an array with a single string number value. It will look a bit like this.

{
  "dependsOn": [ "1" ],
}

Obviously we will have other properties in our request but dependsOn as above will be an additional one now if we’d like to implement sequencing.

An example batch request

So now you might be wondering how a batch request would look that utilises sequencing. Let’s take a look at the example below.

{
  "requests": [
    {
      "id": "1",
      "method": "GET",
      "url": "..."
    },
    {
      "id": "2",
      "dependsOn": [ "1" ],
      "method": "GET",
      "url": "..."
    },
    {
      "id": "3",
      "dependsOn": [ "2" ],
      "method": "GET",
      "url": "..."
    }
  ]
}

In the batch request above, I’m specifiying that the order of requests, should be executed in the order that they are composed. We can see this by looking at how the second request or the request with an id of 2, has its dependOn property set to 1. This means the request with an id of 1 has to have been executed prior to the current one we are looking at which is 2.

The same thing is happening with the request with an id of 3, which relies on request 2 to have been executed prior to it being executed itself.

Overview

So now we’ve taken a look at how to reduce network latency by utilising JSON batching to execute parallel and batched sequential requests towards Microsoft Graph.

Note that when using batching, the batch should either be fully sequential, utilising the dependsOn property except for on the first request, or the batch should be fully parallel, not utilising the dependsOn property at all.

If you didn’t understand something in this blog post, or you need more support on this topic, let me know in the comments below or contact me via my blog chat.

If you’re enjoying my content on Microsoft Graph, Low Code and Microsoft Cloud technologies, be sure to subscribe to get my content directly in your inbox! 📩💖

Written by
Lewis Baybutt
Microsoft Business Applications MVP • Power Platform Consultant • Blogger • Community Contributor • #CommunityRocks • #SharingIsCaring
Comments
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to LewisDoesDev.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.