HttpClient.d.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { AbortSignal } from "./AbortController";
  2. import { MessageHeaders } from "./IHubProtocol";
  3. /** Represents an HTTP request. */
  4. export interface HttpRequest {
  5. /** The HTTP method to use for the request. */
  6. method?: string;
  7. /** The URL for the request. */
  8. url?: string;
  9. /** The body content for the request. May be a string or an ArrayBuffer (for binary data). */
  10. content?: string | ArrayBuffer;
  11. /** An object describing headers to apply to the request. */
  12. headers?: MessageHeaders;
  13. /** The XMLHttpRequestResponseType to apply to the request. */
  14. responseType?: XMLHttpRequestResponseType;
  15. /** An AbortSignal that can be monitored for cancellation. */
  16. abortSignal?: AbortSignal;
  17. /** The time to wait for the request to complete before throwing a TimeoutError. Measured in milliseconds. */
  18. timeout?: number;
  19. /** This controls whether credentials such as cookies are sent in cross-site requests. */
  20. withCredentials?: boolean;
  21. }
  22. /** Represents an HTTP response. */
  23. export declare class HttpResponse {
  24. readonly statusCode: number;
  25. readonly statusText?: string | undefined;
  26. readonly content?: string | ArrayBuffer | undefined;
  27. /** Constructs a new instance of {@link @microsoft/signalr.HttpResponse} with the specified status code.
  28. *
  29. * @param {number} statusCode The status code of the response.
  30. */
  31. constructor(statusCode: number);
  32. /** Constructs a new instance of {@link @microsoft/signalr.HttpResponse} with the specified status code and message.
  33. *
  34. * @param {number} statusCode The status code of the response.
  35. * @param {string} statusText The status message of the response.
  36. */
  37. constructor(statusCode: number, statusText: string);
  38. /** Constructs a new instance of {@link @microsoft/signalr.HttpResponse} with the specified status code, message and string content.
  39. *
  40. * @param {number} statusCode The status code of the response.
  41. * @param {string} statusText The status message of the response.
  42. * @param {string} content The content of the response.
  43. */
  44. constructor(statusCode: number, statusText: string, content: string);
  45. /** Constructs a new instance of {@link @microsoft/signalr.HttpResponse} with the specified status code, message and binary content.
  46. *
  47. * @param {number} statusCode The status code of the response.
  48. * @param {string} statusText The status message of the response.
  49. * @param {ArrayBuffer} content The content of the response.
  50. */
  51. constructor(statusCode: number, statusText: string, content: ArrayBuffer);
  52. /** Constructs a new instance of {@link @microsoft/signalr.HttpResponse} with the specified status code, message and binary content.
  53. *
  54. * @param {number} statusCode The status code of the response.
  55. * @param {string} statusText The status message of the response.
  56. * @param {string | ArrayBuffer} content The content of the response.
  57. */
  58. constructor(statusCode: number, statusText: string, content: string | ArrayBuffer);
  59. }
  60. /** Abstraction over an HTTP client.
  61. *
  62. * This class provides an abstraction over an HTTP client so that a different implementation can be provided on different platforms.
  63. */
  64. export declare abstract class HttpClient {
  65. /** Issues an HTTP GET request to the specified URL, returning a Promise that resolves with an {@link @microsoft/signalr.HttpResponse} representing the result.
  66. *
  67. * @param {string} url The URL for the request.
  68. * @returns {Promise<HttpResponse>} A Promise that resolves with an {@link @microsoft/signalr.HttpResponse} describing the response, or rejects with an Error indicating a failure.
  69. */
  70. get(url: string): Promise<HttpResponse>;
  71. /** Issues an HTTP GET request to the specified URL, returning a Promise that resolves with an {@link @microsoft/signalr.HttpResponse} representing the result.
  72. *
  73. * @param {string} url The URL for the request.
  74. * @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter.
  75. * @returns {Promise<HttpResponse>} A Promise that resolves with an {@link @microsoft/signalr.HttpResponse} describing the response, or rejects with an Error indicating a failure.
  76. */
  77. get(url: string, options: HttpRequest): Promise<HttpResponse>;
  78. /** Issues an HTTP POST request to the specified URL, returning a Promise that resolves with an {@link @microsoft/signalr.HttpResponse} representing the result.
  79. *
  80. * @param {string} url The URL for the request.
  81. * @returns {Promise<HttpResponse>} A Promise that resolves with an {@link @microsoft/signalr.HttpResponse} describing the response, or rejects with an Error indicating a failure.
  82. */
  83. post(url: string): Promise<HttpResponse>;
  84. /** Issues an HTTP POST request to the specified URL, returning a Promise that resolves with an {@link @microsoft/signalr.HttpResponse} representing the result.
  85. *
  86. * @param {string} url The URL for the request.
  87. * @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter.
  88. * @returns {Promise<HttpResponse>} A Promise that resolves with an {@link @microsoft/signalr.HttpResponse} describing the response, or rejects with an Error indicating a failure.
  89. */
  90. post(url: string, options: HttpRequest): Promise<HttpResponse>;
  91. /** Issues an HTTP DELETE request to the specified URL, returning a Promise that resolves with an {@link @microsoft/signalr.HttpResponse} representing the result.
  92. *
  93. * @param {string} url The URL for the request.
  94. * @returns {Promise<HttpResponse>} A Promise that resolves with an {@link @microsoft/signalr.HttpResponse} describing the response, or rejects with an Error indicating a failure.
  95. */
  96. delete(url: string): Promise<HttpResponse>;
  97. /** Issues an HTTP DELETE request to the specified URL, returning a Promise that resolves with an {@link @microsoft/signalr.HttpResponse} representing the result.
  98. *
  99. * @param {string} url The URL for the request.
  100. * @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter.
  101. * @returns {Promise<HttpResponse>} A Promise that resolves with an {@link @microsoft/signalr.HttpResponse} describing the response, or rejects with an Error indicating a failure.
  102. */
  103. delete(url: string, options: HttpRequest): Promise<HttpResponse>;
  104. /** Issues an HTTP request to the specified URL, returning a {@link Promise} that resolves with an {@link @microsoft/signalr.HttpResponse} representing the result.
  105. *
  106. * @param {HttpRequest} request An {@link @microsoft/signalr.HttpRequest} describing the request to send.
  107. * @returns {Promise<HttpResponse>} A Promise that resolves with an HttpResponse describing the response, or rejects with an Error indicating a failure.
  108. */
  109. abstract send(request: HttpRequest): Promise<HttpResponse>;
  110. /** Gets all cookies that apply to the specified URL.
  111. *
  112. * @param url The URL that the cookies are valid for.
  113. * @returns {string} A string containing all the key-value cookie pairs for the specified URL.
  114. */
  115. getCookieString(url: string): string;
  116. }