OpenVeo REST NodeJS client API

API Docs for: 4.0.0
Show:

RestClient

Summary

Creates a client to connect to REST web service.

It aims to facilitate implementation of a REST web service client. Requesting an end point, without being authenticated, will automatically execute the authenticateRequest first before calling the end point. If token expired, a new authentication is made automatically.

You MUST:

  • Extend this class
  • Define a authenticateRequest property with a Request as a value. This will be automatically called by the RestClient to get an access token from the server (response from server should contain the property access_token containing the access token which will be stored in RestClient accessToken property and used for all subsequent requests). Use buildRequest function to create the authenticate request
  • Make sure that the web service server returns a property error_description set to "Token not found or expired" if token couln't be retrieved
  • Make sure that the web service server returns a property error_description set to "Token already expired" if token has expired

You MAY:

  • Override function getAuthenticationHeaders. By default the list of headers returned by getAuthenticationHeaders function will be added to all requests sent to the server. One of this header may be the authentication header for example

Constructor

RestClient

Syntax

RestClient

(
  • webServiceUrl
  • [certificate]
)

Summary

Parameters:

  • webServiceUrl String

    The complete URL of the REST web service (with protocol and port)

  • [certificate] String optional

    Absolute path to the web service server full chain certificate file

Methods

authenticate

Syntax

authenticate

() Promise private async

Summary

Authenticates the client to the web service.

Returns:

Promise:

Promise resolving when the client is authenticated, promise is rejected if authentication failed

buildRequest

Syntax

buildRequest

(
  • [options]
  • [body]
  • [timeout=10000]
  • [multiparted=false]
  • resolve
  • reject
)
Request private

Summary

Builds a request.

Parameters:

  • [options] Object optional

    The list of http(s) options as described by NodeJS http.request documentation

  • [body] Object | String optional

    The request body

  • [timeout=10000] Number optional

    Maximum execution time for the request (in ms), set it to Infinity for a request without limits

  • [multiparted=false] Boolean optional

    true to send body as multipart/form-data

  • resolve Function

    The function to call with request's result

  • reject Function

    The function to call if request fails

Returns:

Request:

The request, ready to be executed

delete

Syntax

delete

(
  • endPoint
  • [options]
  • [timeout=10000]
)
Promise async

Summary

Executes a DELETE request.

If client is not authenticated or access token has expired, a new authentication is automatically performed.

Parameters:

  • endPoint String

    The web service end point to reach with query parameters

  • [options] Object optional

    The list of http(s) options as described by NodeJS http.request documentation

  • [timeout=10000] Number optional

    Maximum execution time for the request (in ms), set it to Infinity for a request without limits

Returns:

Promise:

Promise resolving with results as an Object

executeRequest

Syntax

executeRequest

(
  • method
  • endPoint
  • [options]
  • [body]
  • [timeout=10000]
  • [multiparted=false]
)
Promise private async

Summary

Executes a REST request after making sure the client is authenticated.

If client is not authenticated or access token has expired, a new authentication is automatically performed and request is retried.

Parameters:

  • method String

    The HTTP method to use (either get, post, delete or put)

  • endPoint String

    The web service end point to reach with query parameters

  • [options] Object optional

    The list of http(s) options as described by NodeJS http.request documentation

  • [body] Object | String optional

    The request body

  • [timeout=10000] Number optional

    Maximum execution time for the request (in ms), set it to Infinity for a request without limits

  • [multiparted=false] Boolean optional

    true to send body as multipart/form-data

Returns:

Promise:

Promise resolving with request's response

get

Syntax

get

(
  • endPoint
  • [options]
  • [timeout=10000]
)
Promise async

Summary

Executes a GET request.

If client is not authenticated or access token has expired, a new authentication is automatically performed.

Parameters:

  • endPoint String

    The web service end point to reach with query parameters

  • [options] Object optional

    The list of http(s) options as described by NodeJS http.request documentation

  • [timeout=10000] Number optional

    Maximum execution time for the request (in ms), set it to Infinity for a request without limits

Returns:

Promise:

Promise resolving with result as an Object

getAuthenticationHeaders

Syntax

getAuthenticationHeaders

() Object

Summary

Gets the list of headers to send with each request.

Returns:

Object:

The list of headers to add to all requests sent to the server

getRequestHeaders

Syntax

getRequestHeaders

() Object private

Summary

Gets the list of headers to send with each request.

Returns:

Object:

The list of headers to add to all requests sent to the server

isAuthenticated

Syntax

isAuthenticated

() Boolean private

Summary

Indicates if the client is authenticated to the web service or not.

Returns:

Boolean:

true if the client is authenticated, false otherwise

patch

Syntax

patch

(
  • endPoint
  • [body]
  • [options]
  • [timeout=10000]
  • [multiparted=false]
)
Promise async

Summary

Executes a PATCH request.

If client is not authenticated or access token has expired, a new authentication is automatically performed.

Parameters:

  • endPoint String

    The web service end point to reach with query parameters

  • [body] Object | String optional

    The request body

  • [options] Object optional

    The list of http(s) options as described by NodeJS http.request documentation

  • [timeout=10000] Number optional

    Maximum execution time for the request (in ms), set it to Infinity for a request without limits

  • [multiparted=false] Boolean optional

    true to send body as multipart/form-data

Returns:

Promise:

Promise resolving with results as an Object

post

Syntax

post

(
  • endPoint
  • [body]
  • [options]
  • [timeout=10000]
  • [multiparted=false]
)
Promise async

Summary

Executes a POST request.

If client is not authenticated or access token has expired, a new authentication is automatically performed.

Parameters:

  • endPoint String

    The web service end point to reach with query parameters

  • [body] Object | String optional

    The request body

  • [options] Object optional

    The list of http(s) options as described by NodeJS http.request documentation

  • [timeout=10000] Number optional

    Maximum execution time for the request (in ms), set it to Infinity for a request without limits

  • [multiparted=false] Boolean optional

    true to send body as multipart/form-data

Returns:

Promise:

Promise resolving with results as an Object

put

Syntax

put

(
  • endPoint
  • [body]
  • [options]
  • [timeout=10000]
  • [multiparted=false]
)
Promise async

Summary

Executes a PUT request.

If client is not authenticated or access token has expired, a new authentication is automatically performed.

Parameters:

  • endPoint String

    The web service end point to reach with query parameters

  • [body] Object | String optional

    The request body

  • [options] Object optional

    The list of http(s) options as described by NodeJS http.request documentation

  • [timeout=10000] Number optional

    Maximum execution time for the request (in ms), set it to Infinity for a request without limits

  • [multiparted=false] Boolean optional

    true to send body as multipart/form-data

Returns:

Promise:

Promise resolving with results as an Object

Properties

accessToken

Syntax

accessToken

String

Summary

Application access token provided by the web service.

certificate

Syntax

certificate

String final

Summary

Path to the web service server certificate file.

hostname

Syntax

hostname

String final

Summary

Web service server host name.

maxAuthenticationAttempts

Syntax

maxAuthenticationAttempts

Number

Summary

Maximum number of authentication attempts to perform on a request in case of an invalid or expired token.

Default: 1

path

Syntax

path

String final

Summary

Web service URL path.

port

Syntax

port

Number final

Summary

Web service server port.

protocol

Syntax

protocol

String final

Summary

Web service protocol, either "http" or "https".

queuedRequests

Syntax

queuedRequests

Set

Summary

The collection of queued requests waiting to be executed.