HttpClient class
HttpClient implements a basic set of features for performing REST operations against a generic service.
Remarks
For communicating with SharePoint, use the SPHttpClient class instead.
Constructors
(constructor)(service |
Constructs a new instance of the |
Properties
configurations | The standard predefined HttpClientConfiguration objects for use with the HttpClient class. |
service |
The service key for HttpClient. |
Methods
fetch(url, configuration, options) | Performs a REST service call. |
get(url, configuration, options) | Calls fetch(), but sets the method to "GET". |
post(url, configuration, options) | Calls fetch(), but sets the method to "POST". |
Constructor Details
(constructor)(serviceScope)
Constructs a new instance of the HttpClient
class
constructor(serviceScope: ServiceScope);
Parameters
- serviceScope
- ServiceScope
Property Details
configurations
The standard predefined HttpClientConfiguration objects for use with the HttpClient class.
static readonly configurations: IHttpClientConfigurations;
Property Value
serviceKey
The service key for HttpClient.
static readonly serviceKey: ServiceKey<HttpClient>;
Property Value
Method Details
fetch(url, configuration, options)
Performs a REST service call.
fetch(url: string, configuration: HttpClientConfiguration, options: IHttpClientOptions): Promise<HttpClientResponse>;
Parameters
- url
-
string
the URL to fetch
- configuration
- HttpClientConfiguration
determines the default behavior of HttpClient; normally this should be the latest version number from HttpClientConfigurations
- options
- IHttpClientOptions
additional options that affect the request
Returns
Promise<HttpClientResponse>
A promise with behavior similar to WHATWG fetch(). This promise will resolve normally (with HttpClientResponse.ok being false) for error status codes such as HTTP 404 or 500. The promise will only reject for network failures or other errors that prevent communication with the server.
Remarks
Although the SPHttpClient subclass adds additional enhancements, the parameters and semantics for HttpClient.fetch() are essentially the same as the WHATWG API standard that is documented here: https://fetch.spec.whatwg.org/
get(url, configuration, options)
Calls fetch(), but sets the method to "GET".
get(url: string, configuration: HttpClientConfiguration, options?: IHttpClientOptions): Promise<HttpClientResponse>;
Parameters
- url
-
string
the URL to fetch
- configuration
- HttpClientConfiguration
determines the default behavior of HttpClient; normally this should be the latest version number from HttpClientConfigurations
- options
- IHttpClientOptions
additional options that affect the request
Returns
Promise<HttpClientResponse>
A promise with behavior similar to WHATWG fetch(). This promise will resolve normally (with HttpClientResponse.ok being false) for error status codes such as HTTP 404 or 500. The promise will only reject for network failures or other errors that prevent communication with the server.
post(url, configuration, options)
Calls fetch(), but sets the method to "POST".
post(url: string, configuration: HttpClientConfiguration, options: IHttpClientOptions): Promise<HttpClientResponse>;
Parameters
- url
-
string
the URL to fetch
- configuration
- HttpClientConfiguration
determines the default behavior of HttpClient; normally this should be the latest version number from HttpClientConfigurations
- options
- IHttpClientOptions
additional options that affect the request
Returns
Promise<HttpClientResponse>
A promise with behavior similar to WHATWG fetch(). This promise will resolve normally (with HttpClientResponse.ok being false) for error status codes such as HTTP 404 or 500. The promise will only reject for network failures or other errors that prevent communication with the server.