Skip to main content

Rest

@nuclia/core


@nuclia/core / Rest

Class: Rest

Defined in: libs/sdk-core/src/lib/rest/rest.ts:28

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​

Constructors​

Constructor​

new Rest(nuclia): Rest

Defined in: libs/sdk-core/src/lib/rest/rest.ts:37

Parameters​

nuclia​

INuclia

Returns​

Rest

Methods​

checkAuthorization()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:237

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

Parameters​

endpoint​

string

Returns​

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

Implementation of​

IRest.checkAuthorization


delete()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:86

Type Parameters​

T​

T

Parameters​

path​

string

extraHeaders?​
synchronous?​

boolean

zoneSlug?​

string

Returns​

Observable<T>

Implementation of​

IRest.delete


get()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:41

Type Parameters​

T​

T

Parameters​

path​

string

extraHeaders?​
doNotParse?​

boolean

zoneSlug?​

string

Returns​

Observable<T>

Implementation of​

IRest.get


getAccountZones()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:278

Zone id to slug map, scoped to the account's own zones (unlike getZones(), which is global).

Parameters​

accountIdOrSlug​

string

Returns​

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

Implementation of​

IRest.getAccountZones


getFullUrl()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:191

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​

path​

string

zoneSlug?​

string

insertAuthorizer?​

boolean

Returns​

string

Implementation of​

IRest.getFullUrl


getHeaders()​

getHeaders(method, path, extraHeaders?, synchronous?, formData?): object

Defined in: libs/sdk-core/src/lib/rest/rest.ts:99

Parameters​

method​

string

path​

string

extraHeaders?​
synchronous?​

boolean = false

formData?​

boolean = false

Returns​

object

Implementation of​

IRest.getHeaders


getObjectURL()​

getObjectURL(path): Observable<string>

Defined in: libs/sdk-core/src/lib/rest/rest.ts:316

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​

path​

string

Returns​

Observable<string>

Implementation of​

IRest.getObjectURL


getStreamedResponse()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:331

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​

path​

string

body​

unknown

body to be passed as parameter to the POST request made

extraHeaders?​

Returns​

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

Implementation of​

IRest.getStreamedResponse


getStreamMessages()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:397

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​

path​

string

controller​

AbortController

Returns​

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

Implementation of​

IRest.getStreamMessages


getWsUrl()​

getWsUrl(path, ephemeralToken): string

Defined in: libs/sdk-core/src/lib/rest/rest.ts:500

Parameters​

path​

string

ephemeralToken​

string

Returns​

string

Implementation of​

IRest.getWsUrl


getZoneOrigin()​

getZoneOrigin(slug): string | null | undefined

Defined in: libs/sdk-core/src/lib/rest/rest.ts:293

Returns the custom origin URL for the given zone slug, or null/undefined if not set.

Parameters​

slug​

string

Returns​

string | null | undefined

Implementation of​

IRest.getZoneOrigin


getZones()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:260

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

Returns​

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

Implementation of​

IRest.getZones


getZoneSlug()​

getZoneSlug(zoneId): Observable<string>

Defined in: libs/sdk-core/src/lib/rest/rest.ts:273

Parameters​

zoneId​

string

Returns​

Observable<string>

Implementation of​

IRest.getZoneSlug


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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:95

Parameters​

path​

string

extraHeaders?​

Returns​

Observable<Response>

Implementation of​

IRest.head


patch()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:74

Type Parameters​

T​

T

Parameters​

path​

string

body​

any

extraHeaders?​
doNotParse?​

boolean

synchronous?​

boolean

zoneSlug?​

string

Returns​

Observable<T>

Implementation of​

IRest.patch


post()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:50

Type Parameters​

T​

T

Parameters​

path​

string

body​

any

extraHeaders?​
doNotParse?​

boolean

synchronous?​

boolean

zoneSlug?​

string

Returns​

Observable<T>

Implementation of​

IRest.post


put()​

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

Defined in: libs/sdk-core/src/lib/rest/rest.ts:62

Type Parameters​

T​

T

Parameters​

path​

string

body​

any

extraHeaders?​
doNotParse?​

boolean

synchronous?​

boolean

zoneSlug?​

string

Returns​

Observable<T>

Implementation of​

IRest.put


setZoneOrigins()​

setZoneOrigins(origins): void

Defined in: libs/sdk-core/src/lib/rest/rest.ts:302

Merges the provided slug→origin map into the cached zoneOrigins. Uses "prefer non-null" semantics: a non-null incoming value always wins; an incoming null/undefined does not overwrite an already-known non-null origin.

Parameters​

origins​

Returns​

void

Implementation of​

IRest.setZoneOrigins