@@ -406,6 +406,12 @@ try:
406
406
doc_id = example_doc_id
407
407
).get_result()
408
408
409
+ # Note: for response byte stream use:
410
+ # document_as_byte_stream = client.get_document_as_stream(
411
+ # db=example_db_name,
412
+ # doc_id=example_doc_id
413
+ # ).get_result()
414
+
409
415
# Add Bob Smith's address to the document
410
416
document[" address" ] = " 19 Front Street, Darlington, DL5 1TY"
411
417
@@ -419,6 +425,12 @@ try:
419
425
document = document
420
426
).get_result()
421
427
428
+ # Note: for request byte stream use:
429
+ # update_document_response = client.post_document(
430
+ # db=example_db_name,
431
+ # document=document_as_byte_stream
432
+ # ).get_result()
433
+
422
434
# Keep track with the revision number of the document object:
423
435
document[" _rev" ] = update_document_response[" rev" ]
424
436
print (f ' You have updated the document: \n ' +
@@ -513,13 +525,32 @@ For sample code on handling errors, see
513
525
### Raw IO
514
526
515
527
For endpoints that read or write document content it is possible to bypass
516
- usage of the built-in models and send or receive a bytes response.
517
- For examples of using byte streams, see the API reference documentation
518
- ("Example request as a stream" section).
528
+ usage of the built-in object with byte streams.
529
+
530
+ Depending on the specific SDK operation it may be possible to:
531
+ * accept a user-provided byte stream to send to the server as a request body
532
+ * return a byte stream of the server response body to the user
533
+
534
+ Request byte stream can be supplied for arguments that accept the ` BinaryIO ` type.
535
+ For these cases you can pass this byte stream directly to the HTTP request body.
536
+
537
+ Response byte stream is supported in functions with the suffix of ` _as_stream ` .
538
+ The returned byte stream allows the response body to be consumed
539
+ without triggering JSON unmarshalling that is typically performed by the SDK.
540
+
541
+ The [ update document] ( #3-update-your-previously-created-document ) section
542
+ contains examples for both request and response byte stream cases.
543
+
544
+ The API reference contains further examples of using byte streams.
545
+ They are titled "Example request as stream" and are initially collapsed.
546
+ Expand them to see examples of:
547
+
548
+ - Byte requests:
549
+ - [ Bulk modify multiple documents in a database] ( https://cloud.ibm.com/apidocs/cloudant?code=python#postbulkdocs )
519
550
520
- - [ Bulk modify multiple documents in a database ] ( https://cloud.ibm.com/apidocs/cloudant?code=python#postbulkdocs )
521
- - [ Query a list of all documents in a database] ( https://cloud.ibm.com/apidocs/cloudant?code=python#postalldocs )
522
- - [ Query the database document changes feed] ( https://cloud.ibm.com/apidocs/cloudant?code=python#postchanges )
551
+ - Byte responses:
552
+ - [ Query a list of all documents in a database] ( https://cloud.ibm.com/apidocs/cloudant?code=python#postalldocs )
553
+ - [ Query the database document changes feed] ( https://cloud.ibm.com/apidocs/cloudant?code=python#postchanges )
523
554
524
555
### Further resources
525
556
0 commit comments