httpOperationResponse.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License. See License.txt in the project root for license information.
  3. import { WebResource } from "./webResource";
  4. import { HttpHeaders } from "./httpHeaders";
  5. /**
  6. * The properties on an HTTP response which will always be present.
  7. */
  8. export interface HttpResponse {
  9. /**
  10. * The raw request
  11. */
  12. request: WebResource;
  13. /**
  14. * The HTTP response status (e.g. 200)
  15. */
  16. status: number;
  17. /**
  18. * The HTTP response headers.
  19. */
  20. headers: HttpHeaders;
  21. }
  22. declare global {
  23. /**
  24. * Stub declaration of the browser-only Blob type.
  25. * Full type information can be obtained by including "lib": ["dom"] in tsconfig.json.
  26. */
  27. interface Blob {}
  28. }
  29. /**
  30. * Wrapper object for http request and response. Deserialized object is stored in
  31. * the `parsedBody` property when the response body is received in JSON or XML.
  32. */
  33. export interface HttpOperationResponse extends HttpResponse {
  34. /**
  35. * The parsed HTTP response headers.
  36. */
  37. parsedHeaders?: { [key: string]: any };
  38. /**
  39. * The response body as text (string format)
  40. */
  41. bodyAsText?: string | null;
  42. /**
  43. * The response body as parsed JSON or XML
  44. */
  45. parsedBody?: any;
  46. /**
  47. * BROWSER ONLY
  48. *
  49. * The response body as a browser Blob.
  50. * Always undefined in node.js.
  51. */
  52. blobBody?: Promise<Blob>;
  53. /**
  54. * NODEJS ONLY
  55. *
  56. * The response body as a node.js Readable stream.
  57. * Always undefined in the browser.
  58. */
  59. readableStreamBody?: NodeJS.ReadableStream;
  60. }
  61. /**
  62. * The flattened response to a REST call.
  63. * Contains the underlying HttpOperationResponse as well as
  64. * the merged properties of the parsedBody, parsedHeaders, etc.
  65. */
  66. export interface RestResponse {
  67. /**
  68. * The underlying HTTP response containing both raw and deserialized response data.
  69. */
  70. _response: HttpOperationResponse;
  71. [key: string]: any;
  72. }