GraphHttpClient class

Warning

This API is now obsolete.

The GraphHttpClient class has been superseded by the MSGraphClient class.

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

GraphHttpClient is used to perform REST calls against Microsoft Graph. It adds default headers and collects telemetry that helps the service to monitor the performance of an application. https://developer.microsoft.com/en-us/graph/

Remarks

This class is marked as @sealed. Subclasses should not extend it.

For communicating with SharePoint, use the SPHttpClient class instead. For communicating with other internet services, use the HttpClient class instead.

Constructors

constructor(serviceScope)

Constructs a new instance of the GraphHttpClient class

Properties

configurations

The standard predefined GraphHttpClientConfiguration objects for use with the GraphHttpClient class.

serviceKey

The service key for GraphHttpClient.

Methods

fetch(url, configuration, options)

Perform 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)

Warning

This API is now obsolete.

The GraphHttpClient class has been superseded by the MSGraphClient class.

Constructs a new instance of the GraphHttpClient class

constructor(serviceScope: ServiceScope);

Parameters

serviceScope
ServiceScope

Property Details

configurations

Warning

This API is now obsolete.

The GraphHttpClient class has been superseded by the MSGraphClient class.

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

The standard predefined GraphHttpClientConfiguration objects for use with the GraphHttpClient class.

static readonly configurations: IGraphHttpClientConfigurations;

Property Value

IGraphHttpClientConfigurations

serviceKey

Warning

This API is now obsolete.

The GraphHttpClient class has been superseded by the MSGraphClient class.

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

The service key for GraphHttpClient.

static readonly serviceKey: ServiceKey<GraphHttpClient>;

Property Value

ServiceKey<GraphHttpClient>

Method Details

fetch(url, configuration, options)

Warning

This API is now obsolete.

The GraphHttpClient class has been superseded by the MSGraphClient class.

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Perform a REST service call.

fetch(url: string, configuration: GraphHttpClientConfiguration, options: IGraphHttpClientOptions): Promise<GraphHttpClientResponse>;

Parameters

url
string

The url string should be relative to the graph server. Good: 'v1.0/me/events' Bad: '/v1.0/me/events', 'https://graph.microsoft.com/v1.0/me/events'

configuration
GraphHttpClientConfiguration

determines the default behavior of GraphHttpClient; normally this should be the latest version number from GraphHttpClientConfigurations

options
IGraphHttpClientOptions

additional options that affect the request

Returns

Promise<GraphHttpClientResponse>

a promise that will return the result

Remarks

Generally, 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/

The GraphHttpClient subclass adds some additional behaviors that are convenient when working with SharePoint ODATA API's (which can be avoided by using HttpClient instead): - Default "Accept" and "Content-Type" headers are added if not explicitly specified.

get(url, configuration, options)

Warning

This API is now obsolete.

The GraphHttpClient class has been superseded by the MSGraphClient class.

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Calls fetch(), but sets the method to "GET".

get(url: string, configuration: GraphHttpClientConfiguration, options?: IGraphHttpClientOptions): Promise<GraphHttpClientResponse>;

Parameters

url
string

the URL to fetch

configuration
GraphHttpClientConfiguration

determines the default behavior of GraphHttpClient; normally this should be the latest version number from GraphHttpClientConfigurations

options
IGraphHttpClientOptions

additional options that affect the request

Returns

Promise<GraphHttpClientResponse>

a promise that will return the result

post(url, configuration, options)

Warning

This API is now obsolete.

The GraphHttpClient class has been superseded by the MSGraphClient class.

Note

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Calls fetch(), but sets the method to "POST".

post(url: string, configuration: GraphHttpClientConfiguration, options: IGraphHttpClientOptions): Promise<GraphHttpClientResponse>;

Parameters

url
string

the URL to fetch

configuration
GraphHttpClientConfiguration

determines the default behavior of GraphHttpClient; normally this should be the latest version number from GraphHttpClientConfigurations

options
IGraphHttpClientOptions

additional options that affect the request

Returns

Promise<GraphHttpClientResponse>

a promise that will return the result