Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 2.75 KB

BatchRequestContent.md

File metadata and controls

57 lines (40 loc) · 2.75 KB

BatchRequestContent

Objectives

Provide a class that makes it simple to create the payload for a Graph Batch request.

Requirements

See constraints related to all content objects.

  • It MUST be possible to add native platform HTTP request objects to a BatchRequestContent object. The request URL MUST be a relative URL. Adding Graph specific Request objects MAY be supported.
  • Added requests MUST be assigned unique identifiers. Those identifiers MAY be user provided or autogenerated.
  • It MUST be possible to create dependencies between request objects.
  • The serialized representation, written to a stream, or returned as a byte array MUST be a JSON object that conforms to the format described in the Graph Documentation and OData specification. Request bodies must be base64 encoded.
  • It MUST be possible to use a dictionary of existing unique identifiers and their corresponding to response status code to create a new/fresh BatchRequestContent instance to unlock re-emitting/retrying failed requests from an existing BatchRequestContent instance.

Performance Considerations

A batch cannot hold more that 20 requests and requests cannot contain a batch request payload.

Security Considerations

Requests that require additional consent, not already obtained, should not be included in a batch.

Usage Examples

// create the batch request
var batchRequestContent = new BatchRequestContent(graphServiceClient);
var requestInformation = graphServiceClient.Users.ToGetRequestInformation();

// add step using requestInformation
var requestStepId = await batchRequestContent.AddBatchRequestStepAsync(requestInformation);

// add step using native platform HTTP request
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me");
var secondRequestStepId = batchRequestContent.AddBatchRequestStep(httpRequestMessage);

// send and get back response
var batchResponseContent = await graphServiceClient.Batch.PostAsync(batchRequestContent);

// enumerate list of response status codes
var statusCodes = await batchResponseContent.GetResponsesStatusCodesAsync();
// filter the requests to retry
var rateLimitedResponses = statusCodes.Where(x => x.Value == HttpStatusCode.TooManyRequests).ToDictionary(x => x.Key,y => y.Value); 
if (rateLimitedResponses.Any())
{
    var retryBatch = batchRequestContent.NewBatchWithFailedRequests(rateLimitedResponses);
    // send and get back response
    var retryBatchResponseContent = await graphServiceClient.Batch.PostAsync(retryBatch);
}

References

  1. Graph Documentation
  2. OData