msgraph-sdk-javascript icon indicating copy to clipboard operation
msgraph-sdk-javascript copied to clipboard

Batching - Node

Open jdolearydl opened this issue 7 years ago • 2 comments

The documentation on batching makes use of the Browser's Request object.

How can the same thing be done in Nodejs?

jdolearydl avatar Aug 07 '19 15:08 jdolearydl

It's very similar to what we do for the browser. Example:

async function testfunc()
{
try{
let photoRequest = new Request('/me/photo/$value', {
method: 'GET'
});
let meRequest = new Request('/me', {
method: 'GET'
});
let batchRequestContent = new MicrosoftGraph.BatchRequestContent([
{
request: photoRequest,
id: '1'
},
{
request: meRequest,
id: '2'
}
]);
let content = await batchRequestContent.getContent();
let response = await client
.api('$batch')
.post(content);
let batchResponse = new MicrosoftGraph.BatchResponseContent(response);
let responses = batchResponse.getResponses();

let me = await responses.get('2').json();

//let me = response.responses[0].body
}
catch(e)
{
console.log(e);
}
}

testfunc();

krototype avatar Sep 17 '19 09:09 krototype

Closing this issue, for now. Feel free to open the issue, if needed.

krototype avatar Sep 17 '19 09:09 krototype