Skip to main content

@nuclia/core / Exports / Rest

Class: Rest

Handles the elementary REST requests to the Nuclia backend, setting the appropriate HTTP headers.

Its main methods implement the corresponding HTTP verbs (GET is get(), POST is post(), etc.) For each of them, extraHeaders is an optional parameter that can be used to add headers to the request.

On POST, PUT, PATCH and DELETE, the synchronous parameter will make the call synchronous, meaning the response will be returned only when the operation is fully completed. It is false by default.

The default headers set by Nuclia.rest are:

  • 'content-type': 'application/json'
  • Authorization or X-NUCLIA-SERVICEACCOUNT depending on the type of authentication.

The default headers will be overridden by extraHeaders if they have the same entries.

doNotParse is a boolean that can be used to disable the automatic JSON parsing of the response.

Implements

Table of contents

Constructors

Methods

Constructors

constructor

new Rest(nuclia)

Parameters

NameType
nucliaINuclia

Defined in

libs/sdk-core/src/lib/rest/rest.ts:32

Methods

checkAuthorization

checkAuthorization(endpoint): Observable<{ allowed: boolean ; roles: (KBRoles | NucliaDBRole)[] }>

Check if the user has access to the given endpoint, and return the corresponding roles.

Parameters

NameType
endpointstring

Returns

Observable<{ allowed: boolean ; roles: (KBRoles | NucliaDBRole)[] }>

Implementation of

IRest.checkAuthorization

Defined in

libs/sdk-core/src/lib/rest/rest.ts:218


delete

delete<T>(path, extraHeaders?, synchronous?, zoneSlug?): Observable<T>

Type parameters

Name
T

Parameters

NameType
pathstring
extraHeaders?Object
synchronous?boolean
zoneSlug?string

Returns

Observable<T>

Implementation of

IRest.delete

Defined in

libs/sdk-core/src/lib/rest/rest.ts:81


get

get<T>(path, extraHeaders?, doNotParse?, zoneSlug?): Observable<T>

Type parameters

Name
T

Parameters

NameType
pathstring
extraHeaders?Object
doNotParse?boolean
zoneSlug?string

Returns

Observable<T>

Implementation of

IRest.get

Defined in

libs/sdk-core/src/lib/rest/rest.ts:36


getFullUrl

getFullUrl(path, zoneSlug?, insertAuthorizer?): string

Returns the full URL of the given path, using the regional or the global Nuclia backend according to the path or the provided zone slug (if any).

Parameters

NameType
pathstring
zoneSlug?string
insertAuthorizer?boolean

Returns

string

Implementation of

IRest.getFullUrl

Defined in

libs/sdk-core/src/lib/rest/rest.ts:176


getHeaders

getHeaders(method, path, extraHeaders?, synchronous?): Object

Parameters

NameTypeDefault value
methodstringundefined
pathstringundefined
extraHeaders?Objectundefined
synchronousbooleanfalse

Returns

Object

Implementation of

IRest.getHeaders

Defined in

libs/sdk-core/src/lib/rest/rest.ts:94


getObjectURL

getObjectURL(path): Observable<string>

Downloads the file, converts it to a BLOB and returns its blob: URL.

Use carefully with big files as it can impact the memory.

Parameters

NameType
pathstring

Returns

Observable<string>

Implementation of

IRest.getObjectURL

Defined in

libs/sdk-core/src/lib/rest/rest.ts:254


getStreamMessages

getStreamMessages(path, controller): Observable<{ data: Uint8Array ; headers: Headers }>

Call a long polling HTTP endpoint streaming its response until the connection times out. This method is keeping the connection alive by calling the endpoint again when it times out until the provided controller receives an abort signal (or if the endpoint returns an error unrelated to the timeout).

Parameters

NameType
pathstring
controllerAbortController

Returns

Observable<{ data: Uint8Array ; headers: Headers }>

Implementation of

IRest.getStreamMessages

Defined in

libs/sdk-core/src/lib/rest/rest.ts:335


getStreamedResponse

getStreamedResponse(path, body): Observable<{ data: Uint8Array ; headers: Headers ; incomplete: boolean }>

Call an endpoint streaming its response by batch of data, concatenate the data with the batch received previously until the response is marked as completed and then close the connection.

Parameters

NameTypeDescription
pathstring
bodyunknownbody to be passed as parameter to the POST request made

Returns

Observable<{ data: Uint8Array ; headers: Headers ; incomplete: boolean }>

Implementation of

IRest.getStreamedResponse

Defined in

libs/sdk-core/src/lib/rest/rest.ts:269


getZoneSlug

getZoneSlug(zoneId): Observable<string>

Parameters

NameType
zoneIdstring

Returns

Observable<string>

Implementation of

IRest.getZoneSlug

Defined in

libs/sdk-core/src/lib/rest/rest.ts:245


getZones

getZones(): Observable<{ [key: string]: string; }>

Returns a dictionary giving the geographical zones available slugs by unique ids.

Returns

Observable<{ [key: string]: string; }>

Implementation of

IRest.getZones

Defined in

libs/sdk-core/src/lib/rest/rest.ts:229


head(path, extraHeaders?): Observable<Response>

Parameters

NameType
pathstring
extraHeaders?Object

Returns

Observable<Response>

Implementation of

IRest.head

Defined in

libs/sdk-core/src/lib/rest/rest.ts:90


patch

patch<T>(path, body, extraHeaders?, doNotParse?, synchronous?, zoneSlug?): Observable<T>

Type parameters

Name
T

Parameters

NameType
pathstring
bodyany
extraHeaders?Object
doNotParse?boolean
synchronous?boolean
zoneSlug?string

Returns

Observable<T>

Implementation of

IRest.patch

Defined in

libs/sdk-core/src/lib/rest/rest.ts:69


post

post<T>(path, body, extraHeaders?, doNotParse?, synchronous?, zoneSlug?): Observable<T>

Type parameters

Name
T

Parameters

NameType
pathstring
bodyany
extraHeaders?Object
doNotParse?boolean
synchronous?boolean
zoneSlug?string

Returns

Observable<T>

Implementation of

IRest.post

Defined in

libs/sdk-core/src/lib/rest/rest.ts:45


put

put<T>(path, body, extraHeaders?, doNotParse?, synchronous?, zoneSlug?): Observable<T>

Type parameters

Name
T

Parameters

NameType
pathstring
bodyany
extraHeaders?Object
doNotParse?boolean
synchronous?boolean
zoneSlug?string

Returns

Observable<T>

Implementation of

IRest.put

Defined in

libs/sdk-core/src/lib/rest/rest.ts:57