@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
orX-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
- checkAuthorization
- delete
- get
- getFullUrl
- getHeaders
- getObjectURL
- getStreamMessages
- getStreamedResponse
- getZoneSlug
- getZones
- head
- patch
- post
- put
Constructors
constructor
• new Rest(nuclia
)
Parameters
Name | Type |
---|---|
nuclia | INuclia |
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
Name | Type |
---|---|
endpoint | string |
Returns
Observable
<{ allowed
: boolean
; roles
: (KBRoles
| NucliaDBRole
)[] }>
Implementation of
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
Name | Type |
---|---|
path | string |
extraHeaders? | Object |
synchronous? | boolean |
zoneSlug? | string |
Returns
Observable
<T
>
Implementation of
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
Name | Type |
---|---|
path | string |
extraHeaders? | Object |
doNotParse? | boolean |
zoneSlug? | string |
Returns
Observable
<T
>
Implementation of
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
Name | Type |
---|---|
path | string |
zoneSlug? | string |
insertAuthorizer? | boolean |
Returns
string
Implementation of
Defined in
libs/sdk-core/src/lib/rest/rest.ts:176
getHeaders
▸ getHeaders(method
, path
, extraHeaders?
, synchronous?
): Object
Parameters
Name | Type | Default value |
---|---|---|
method | string | undefined |
path | string | undefined |
extraHeaders? | Object | undefined |
synchronous | boolean | false |
Returns
Object
Implementation of
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
Name | Type |
---|---|
path | string |
Returns
Observable
<string
>
Implementation of
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
Name | Type |
---|---|
path | string |
controller | AbortController |
Returns
Observable
<{ data
: Uint8Array
; headers
: Headers
}>
Implementation of
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
Name | Type | Description |
---|---|---|
path | string | |
body | unknown | body to be passed as parameter to the POST request made |
Returns
Observable
<{ data
: Uint8Array
; headers
: Headers
; incomplete
: boolean
}>
Implementation of
Defined in
libs/sdk-core/src/lib/rest/rest.ts:269
getZoneSlug
▸ getZoneSlug(zoneId
): Observable
<string
>
Parameters
Name | Type |
---|---|
zoneId | string |
Returns
Observable
<string
>
Implementation of
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
Defined in
libs/sdk-core/src/lib/rest/rest.ts:229