Skip to content

Commit e6a99a6

Browse files
committed
update samples
1 parent 9fa9444 commit e6a99a6

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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())

samples/batch_requests/batch_request_with_parsable_as_response_type.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@
5353
batch_content = BatchRequestContent(batch_request_content)
5454

5555

56+
# Function to demonstrate the usage of BatchRequestBuilder
5657
async 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

6670
asyncio.run(main())
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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())

0 commit comments

Comments
 (0)