File tree Expand file tree Collapse file tree 3 files changed +62
-7
lines changed
Expand file tree Collapse file tree 3 files changed +62
-7
lines changed Original file line number Diff line number Diff line change 1+ # ------------------------------------
2+ # Copyright (c) Microsoft Corporation.
3+ # Licensed under the MIT License.
4+ # ------------------------------------
5+ #pylint: disable=undefined-variable
6+ """ Demonstrate getting response body as stream in Batch Responses"""
7+ batch_request_content = {
8+ batch_request_item1 .id : batch_request_item1 ,
9+ batch_request_item2 .id : batch_request_item2
10+ }
11+
12+ batch_content = BatchRequestContent (batch_request_content )
13+
14+
15+ async def main ():
16+ batch_response_content = await batch_request_builder .post (batch_request_content = batch_content )
17+
18+ try :
19+ stream_response = batch_response_content .get_response_stream_by_id (batch_request_item1 .id )
20+ print (f"Stream Response: { stream_response } " )
21+ print (f"Stream Response Content: { stream_response .read ()} " )
22+ except AttributeError as e :
23+ print (f"Error getting response by ID: { e } " )
24+
25+
26+ asyncio .run (main ())
Original file line number Diff line number Diff line change 5353batch_content = BatchRequestContent (batch_request_content )
5454
5555
56+ # Function to demonstrate the usage of BatchRequestBuilder
5657async def main ():
57- # Send the batch request and get the response content
58- batch_response_content = await batch_request_builder .post (
59- batch_request_content = batch_content , response_type = User
60- )
61-
62- # Print the batch response content - User model type
63- print (f"Batch Response Content: { batch_response_content } " )
58+ batch_response_content = await batch_request_builder .post (batch_request_content = batch_content )
59+ # response_type=User
60+
61+ try :
62+ individual_response = batch_response_content .get_response_by_id (
63+ batch_request_item1 .id , User
64+ )
65+ print (f"Individual Response: { individual_response } " )
66+ except AttributeError as e :
67+ print (f"Error getting response by ID: { e } " )
6468
6569
6670asyncio .run (main ())
Original file line number Diff line number Diff line change 1+ # ------------------------------------
2+ # Copyright (c) Microsoft Corporation.
3+ # Licensed under the MIT License.
4+ # ------------------------------------
5+ #pylint: disable=undefined-variable
6+ """Demonstrates getting status codes in Batch Responses"""
7+ batch_request_content = {
8+ batch_request_item1 .id : batch_request_item1 ,
9+ batch_request_item2 .id : batch_request_item2
10+ }
11+
12+ batch_content = BatchRequestContent (batch_request_content )
13+
14+
15+ async def main ():
16+ batch_response_content = await batch_request_builder .post (batch_request_content = batch_content )
17+
18+ try :
19+ status_codes = batch_response_content .get_response_status_codes ()
20+ print (f"Status Codes: { status_codes } " )
21+ except AttributeError as e :
22+ print (f"Error getting respons status codes: { e } " )
23+
24+
25+ asyncio .run (main ())
You can’t perform that action at this time.
0 commit comments