Skip to main content

Rest

@nuclia/coreDocs


@nuclia/core / 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

Constructors

new Rest()

new Rest(nuclia): Rest

Parameters

nuclia: INuclia

Returns

Rest

Defined in

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

Methods

checkAuthorization()

checkAuthorization(endpoint): Observable<object>

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

Parameters

endpoint: string

Returns

Observable<object>

allowed

allowed: boolean

roles

roles: (NucliaDBRole | KBRoles)[]

Implementation of

IRest.checkAuthorization

Defined in

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


delete()

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

Type Parameters

T

Parameters

path: string

extraHeaders?

synchronous?: boolean

zoneSlug?: string

Returns

Observable<T>

Implementation of

IRest.delete

Defined in

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


get()

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

Type Parameters

T

Parameters

path: string

extraHeaders?

doNotParse?: boolean

zoneSlug?: string

Returns

Observable<T>

Implementation of

IRest.get

Defined in

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


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

path: string

zoneSlug?: string

insertAuthorizer?: boolean

Returns

string

Implementation of

IRest.getFullUrl

Defined in

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


getHeaders()

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

Parameters

method: string

path: string

extraHeaders?

synchronous?: boolean = false

Returns

object

Implementation of

IRest.getHeaders

Defined in

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


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

path: string

Returns

Observable<string>

Implementation of

IRest.getObjectURL

Defined in

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


getStreamedResponse()

getStreamedResponse(path, body, extraHeaders?): Observable<object>

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<object>

data

data: Uint8Array<ArrayBufferLike>

headers

headers: Headers

incomplete

incomplete: boolean

Implementation of

IRest.getStreamedResponse

Defined in

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


getStreamMessages()

getStreamMessages(path, controller): Observable<object>

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<object>

data

data: Uint8Array<ArrayBufferLike>

headers

headers: Headers

Implementation of

IRest.getStreamMessages

Defined in

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


getWsUrl()

getWsUrl(path, ephemeralToken): string

Parameters

path: string

ephemeralToken: string

Returns

string

Implementation of

IRest.getWsUrl

Defined in

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


getZones()

getZones(): Observable<object>

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

Returns

Observable<object>

Implementation of

IRest.getZones

Defined in

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


getZoneSlug()

getZoneSlug(zoneId): Observable<string>

Parameters

zoneId: string

Returns

Observable<string>

Implementation of

IRest.getZoneSlug

Defined in

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


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

Parameters

path: string

extraHeaders?

Returns

Observable<Response>

Implementation of

IRest.head

Defined in

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


patch()

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

Type Parameters

T

Parameters

path: string

body: any

extraHeaders?

doNotParse?: boolean

synchronous?: boolean

zoneSlug?: string

Returns

Observable<T>

Implementation of

IRest.patch

Defined in

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


post()

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

Type Parameters

T

Parameters

path: string

body: any

extraHeaders?

doNotParse?: boolean

synchronous?: boolean

zoneSlug?: string

Returns

Observable<T>

Implementation of

IRest.post

Defined in

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


put()

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

Type Parameters

T

Parameters

path: string

body: any

extraHeaders?

doNotParse?: boolean

synchronous?: boolean

zoneSlug?: string

Returns

Observable<T>

Implementation of

IRest.put

Defined in

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