HttpClient.d.ts 6.6 KB

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