---
title: "@dynatrace-sdk/http-client"
description: An environment agnostic (browser/deno vs nodejs) abstraction layer for making HTTP calls.
---


An environment agnostic (browser/deno vs nodejs) abstraction layer for making HTTP calls.

import NpmLogo from '@site/static/img/npm-logo.png';

<div class="row margin-bottom--md">
  <div class="col">
    <a href="https://www.npmjs.com/package/@dynatrace-sdk/http-client" target="_blank" rel="noopener noreferrer"> <span class="margin-right--xs">@dynatrace-sdk/http-client</span> <img className="no-zoom" width="20px" src={NpmLogo} /> </a>
  </div>
  <div class="col" style={{textAlign: 'right'}}>
    <a href="https://www.npmjs.com/package/@dynatrace-sdk/http-client/v/1.5.2" target="_blank" rel="noopener noreferrer">v1.5.2</a>
  </div>
</div>

```bash
npm install @dynatrace-sdk/http-client
```


## Classes

### PlatformBaseError



#### Constructors

##### new PlatformBaseError(message,cause?)
<div class="padding-left--md">

#### Parameters

| Name | Type |
| --- | --- |
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|




</div>



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)||


### PlatformBinary
Represents an environment agnostic (browser vs node) abstraction layer for binary data.


#### Properties

| Name | Type |
| --- | --- |
|data<sup>*required</sup>|ArrayBuffer &#124; Blob &#124; ReadableStream&lt;Uint8Array&gt;|

#### Methods



##### get

<div class="padding-bottom--md">
<strong>get(type): DataTypes&lt;T&gt;</strong>

<div class="padding-left--md">

Returns the binary data in a form that conforms to the specified type.



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|type<sup>*required</sup>|T|<p>The type of the data. Can be <code>text</code>, <code>json</code>, <code>array-buffer</code>, <code>blob</code>, <code>readable-stream</code>, <code>buffer</code> or <code>stream</code>.</p> |





#### Throws

| Error Type | Error Message |
|---|---|
|DataTypeError|Data does not conform to the specified type.|
|UnsupportedOperationError|Type is not supported by the platform.|




</div>





##### from

<div class="padding-bottom--md">
<strong>from(data): [Binary](#binary)</strong>

<div class="padding-left--md">





</div>


#### Parameters

| Name | Type |
| --- | --- |
|data<sup>*required</sup>|ArrayBuffer &#124; Blob &#124; ReadableStream&lt;Uint8Array&gt; &#124; Buffer &#124; Readable|








</div>





##### fromJson

<div class="padding-bottom--md">
<strong>fromJson(json): [Binary](#binary)</strong>

<div class="padding-left--md">





</div>


#### Parameters

| Name | Type |
| --- | --- |
|json<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|








</div>





##### fromText

<div class="padding-bottom--md">
<strong>fromText(text): [Binary](#binary)</strong>

<div class="padding-left--md">





</div>


#### Parameters

| Name | Type |
| --- | --- |
|text<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|








</div>




### PlatformDataTypeError



#### Constructors

##### new PlatformDataTypeError(message,cause?)
<div class="padding-left--md">

#### Parameters

| Name | Type |
| --- | --- |
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|




</div>



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"DataTypeError"|The error name.|


### PlatformHttpClient
The http client that serves as an environment agnostic (browser vs node) abstraction for making http calls.
It handles the authentication of the requests made to the Platform Services and the Serverless Functions.

Currently, only the requests to the Platform Services and the Serverless Functions are supported.


#### Constructors

##### new PlatformHttpClient(options?)
<div class="padding-left--md">

#### Parameters

| Name | Type |
| --- | --- |
|options|HttpClientConfiguration|




</div>



#### Properties

| Name | Type |
| --- | --- |
|_baseUrl<sup>*required</sup>|undefined &#124; [string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|_defaultHeaders<sup>*required</sup>|undefined &#124; [Headers](#headers)|

#### Methods



##### send

<div class="padding-bottom--md">
<strong>send(options): Promise&lt;[HttpClientResponse](#httpclientresponse)&gt;</strong>

<div class="padding-left--md">

Sends an http request as configured by the `options`.
Returns a promise that resolves with a response object for successful requests or rejects with an appropriate error
when one of the following situations happen:
- `DataTypeError` - request body does not conform to the specified request body type,
- `HttpClientRequestError` - request cannot be sent (e.g. due to network error or invalid request),
- `HttpClientResponseError` - response status is considered invalid by the status validator,
- `HttpClientAbortError` - request was aborted.



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|options<sup>*required</sup>|[HttpClientRequestOptions](#httpclientrequestoptions)&lt;T&gt;|Options used to configure the request.|




#### Returns

| Description |
|---|
|Promise&lt;HttpClientResponse&gt; A promise that resolves with the response object or rejects with an error.|





</div>




### PlatformHttpClientAbortError
Represents a situation when the request was aborted.


#### Constructors

##### new PlatformHttpClientAbortError(cause)
<div class="padding-left--md">

#### Parameters

| Name | Type |
| --- | --- |
|cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|




</div>



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"AbortError"|The error name.|


### PlatformHttpClientRequestError
Represents a situation when the request is invalid and cannot be sent.


#### Constructors

##### new PlatformHttpClientRequestError(cause)
<div class="padding-left--md">

#### Parameters

| Name | Type |
| --- | --- |
|cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|




</div>



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"RequestError"|The error name.|


### PlatformHttpClientResponse
Represents the response to a request.


#### Constructors

##### new PlatformHttpClientResponse(response,data?)
<div class="padding-left--md">

#### Parameters

| Name | Type |
| --- | --- |
|response<sup>*required</sup>|Response|
|data|\{ requestUrl \}|
|data.requestUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|




</div>



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|requestUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The URL that was originally requested, before any redirects were followed.|
|response<sup>*required</sup>|Response||

#### Accessors

##### headers
The response headers.


##### status
The status code of the response.


##### statusText
The status message corresponding to the status code.


##### url
The URL of the response. May differ from `requestUrl` if the request was
redirected.


#### Methods



##### body

<div class="padding-bottom--md">
<strong>body(responseBodyType): ResponseBodyTypes&lt;T&gt;</strong>

<div class="padding-left--md">

Returns the response body in a form that conforms to the specified response body type.



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|responseBodyType<sup>*required</sup>|T|<p>The type of the response body. Can be <code>text</code>, <code>json</code>, <code>binary</code>, <code>form-data</code>, <code>array-buffer</code>, <code>blob</code>, <code>readable-stream</code>, <code>buffer</code> or <code>stream</code>. The default response body type is <code>json</code>.</p> |





#### Throws

| Error Type | Error Message |
|---|---|
|DataTypeError|Response body does not conform to the specified response body type.|
|UnsupportedOperationError|Response body type is not supported by the platform.|




</div>




### PlatformHttpClientResponseError
Represents a situation when the response status is considered invalid by the status validator.


#### Constructors

##### new PlatformHttpClientResponseError(response,data?)
<div class="padding-left--md">

#### Parameters

| Name | Type |
| --- | --- |
|response<sup>*required</sup>|Response|
|data|\{ requestMethod, requestUrl \}|
|data.requestMethod|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|data.requestUrl|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|




</div>



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"ResponseError"|The error name.|
|requestMethod|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)||
|response<sup>*required</sup>|[HttpClientResponse](#httpclientresponse)|The response.|


### PlatformUnsupportedOperationError



#### Constructors

##### new PlatformUnsupportedOperationError(message,cause?)
<div class="padding-left--md">

#### Parameters

| Name | Type |
| --- | --- |
|message<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|




</div>



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"UnsupportedOperationError"|The error name.|


## Functions



### isHttpClientAbortError

<div class="padding-bottom--md">
<strong>isHttpClientAbortError(e): </strong>

<div class="padding-left--md">





</div>


#### Parameters

| Name | Type |
| --- | --- |
|e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|








</div>





### isHttpClientNetworkError

<div class="padding-bottom--md">
<strong>isHttpClientNetworkError(e): </strong>

<div class="padding-left--md">





</div>


#### Parameters

| Name | Type |
| --- | --- |
|e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|








</div>





### isHttpClientRequestError

<div class="padding-bottom--md">
<strong>isHttpClientRequestError(e): </strong>

<div class="padding-left--md">





</div>


#### Parameters

| Name | Type |
| --- | --- |
|e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|








</div>





### isHttpClientResponseError

<div class="padding-bottom--md">
<strong>isHttpClientResponseError(e): </strong>

<div class="padding-left--md">





</div>


#### Parameters

| Name | Type |
| --- | --- |
|e<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|








</div>



## Constants

### PlatformAbortController
<div class="padding-left--md">



</div>

<div class="padding-left--md">
() => [AbortController](#abortcontroller)

</div>

### PlatformAbortSignal
<div class="padding-left--md">



</div>

<div class="padding-left--md">
() => AbortSignal

</div>

### httpClient
<div class="padding-left--md">



</div>

<div class="padding-left--md">
[HttpClient](#httpclient)

</div>

## Types

### AbortController
Represents a controller object that allows to abort one or more requests as and when desired.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|signal<sup>*required</sup>|AbortSignal|Returns an AbortSignal object instance, which can be used to communicate with a request.|

#### Methods



##### abort

<div class="padding-bottom--md">
<strong>abort(): void</strong>

<div class="padding-left--md">

Aborts a request before it has completed.



</div>







</div>




### BaseError



#### Properties

| Name | Type |
| --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|


### Binary
Represents an environment agnostic (browser vs node) abstraction layer for binary data.


#### Methods



##### get

<div class="padding-bottom--md">
<strong>get(type): DataTypes&lt;T&gt;</strong>

<div class="padding-left--md">

Returns the binary data in a form that conforms to the specified type.



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|type<sup>*required</sup>|T|<p>The type of the data. Can be <code>text</code>, <code>json</code>, <code>array-buffer</code>, <code>blob</code>, <code>readable-stream</code>, <code>buffer</code> or <code>stream</code>.</p> |





#### Throws

| Error Type | Error Message |
|---|---|
|DataTypeError|Data does not conform to the specified type.|
|UnsupportedOperationError|Type is not supported by the platform.|




</div>




### BinaryFormDataRequestField
Represents an binary field.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|contentType|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The content type of the data contained in <code>value</code>. The default content type for the binary is 'application/octet-stream'.</p> |
|filename|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The filename reported to the server. The default filename for the binary is 'binary'.</p> |
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The name of the field.|
|type<sup>*required</sup>|"binary"|A binary field type discriminator.|
|value<sup>*required</sup>|ArrayBuffer &#124; Blob &#124; Buffer &#124; Readable &#124; [Binary](#binary) &#124; ReadableStream&lt;[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)&gt; &#124; File|The field's value.|


### BinaryFormDataResponseField



#### Properties

| Name | Type |
| --- | --- |
|contentType<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|filename<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|type<sup>*required</sup>|"binary"|
|value<sup>*required</sup>|[Binary](#binary)|


### DataTypeError



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"DataTypeError"|The error name.|


### Headers
Represents http headers.


### HttpClient
The http client that serves as an environment agnostic (browser vs node) abstraction for making http calls.
It handles the authentication of the requests made to the Platform Services and the Serverless Functions.

Currently, only the requests to the Platform Services and the Serverless Functions are supported.


#### Methods



##### send

<div class="padding-bottom--md">
<strong>send(options): Promise&lt;[HttpClientResponse](#httpclientresponse)&gt;</strong>

<div class="padding-left--md">

Sends an http request as configured by the `options`.
Returns a promise that resolves with a response object for successful requests or rejects with an appropriate error
when one of the following situations happen:
- `DataTypeError` - request body does not conform to the specified request body type,
- `HttpClientRequestError` - request cannot be sent (e.g. due to network error or invalid request),
- `HttpClientResponseError` - response status is considered invalid by the status validator,
- `HttpClientAbortError` - request was aborted.



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|options<sup>*required</sup>|[HttpClientRequestOptions](#httpclientrequestoptions)&lt;T&gt;|Options used to configure the request.|




#### Returns

| Description |
|---|
|Promise&lt;HttpClientResponse&gt; A promise that resolves with the response object or rejects with an error.|





</div>




### HttpClientAbortError
Represents a situation when the request was aborted.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"AbortError"|The error name.|


### HttpClientNetworkError
Represents a situation when a network error occurred.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"NetworkError"|The error name.|


### HttpClientRequestError
Represents a situation when the request is invalid and cannot be sent.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"RequestError"|The error name.|


### HttpClientRequestOptions
Represents the options used to configure the request.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|body|RequestBodyTypes&lt;T&gt;|<p>A request body that will be send along with the request. The structure of the request body needs to conform to the specified request body type.</p> |
|headers|[Headers](#headers)|The request headers.|
|method|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The request method, e.g. <code>GET</code>, <code>POST</code>.|
|requestBodyType|T|<p>The type of the request body. Can be <code>text</code>, <code>json</code>, <code>binary</code> or <code>form-data</code>. The default request body type is <code>json</code>.</p> |
|statusValidator|[StatusValidator](#statusvalidator)|<p>A custom status validator function. If the status validator function returns <code>true</code> the returned promise resolves with the <code>HttpClientResponse</code> Otherwise the promise rejects with the <code>StatusError</code>. The default status validator function considers the <code>2xx</code> status codes as valid.</p> |
|url<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The URL of the resource to fetch.|


### HttpClientResponse
Represents the response to a request.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|headers<sup>*required</sup>|[Headers](#headers)|The response headers.|
|requestUrl<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The URL that was originally requested, before any redirects were followed.|
|status<sup>*required</sup>|[number](https://developer.mozilla.org/en-US/docs/Glossary/Number)|The status code of the response.|
|statusText<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The status message corresponding to the status code.|
|url<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The URL of the response. May differ from <code>requestUrl</code> if the request was redirected.</p> |

#### Methods



##### body

<div class="padding-bottom--md">
<strong>body(responseBodyType?): ResponseBodyTypes&lt;T&gt;</strong>

<div class="padding-left--md">

Returns the response body in a form that conforms to the specified response body type.



</div>


#### Parameters

| Name | Type | Description |
| --- | --- | --- |
|responseBodyType|T|<p>The type of the response body. Can be <code>text</code>, <code>json</code>, <code>binary</code>, <code>form-data</code>, <code>array-buffer</code>, <code>blob</code>, <code>readable-stream</code>, <code>buffer</code> or <code>stream</code>. The default response body type is <code>json</code>.</p> |





#### Throws

| Error Type | Error Message |
|---|---|
|DataTypeError|Response body does not conform to the specified response body type.|
|UnsupportedOperationError|Response body type is not supported by the platform.|




</div>




### HttpClientResponseError
Represents a situation when the response status is considered invalid by the status validator.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"ResponseError"|The error name.|
|response<sup>*required</sup>|[HttpClientResponse](#httpclientresponse)|The response.|


### JsonFormDataRequestField
Represents a JSON field.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|contentType|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The content type of the data contained in <code>value</code>. The default content type for the JSON is 'application/json'.</p> |
|filename|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|<p>The filename reported to the server. The default filename for the JSON is 'json'.</p> |
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The name of the field.|
|type<sup>*required</sup>|"json"|A JSON field type discriminator.|
|value<sup>*required</sup>|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The field's value.|


### StatusValidator
Represents a function used to validate the response status code.
If `true` is returned, the status is considered valid (request succeeded), otherwise it&apos;s considered invalid (request failed).


### TextFormDataRequestField
Represents a plain text field. No filename and content type is set.


#### Properties

| Name | Type | Description |
| --- | --- | --- |
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The name of the field.|
|type<sup>*required</sup>|"text"|A plain text field type discriminator.|
|value<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|The field's value.|


### TextFormDataResponseField



#### Properties

| Name | Type |
| --- | --- |
|name<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|
|type<sup>*required</sup>|"text"|
|value<sup>*required</sup>|[string](https://developer.mozilla.org/en-US/docs/Glossary/String)|


### UnsupportedOperationError



#### Properties

| Name | Type | Description |
| --- | --- | --- |
|cause|[any](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)|The error root cause.|
|name<sup>*required</sup>|"UnsupportedOperationError"|The error name.|


