Options
All
  • Public
  • Public/Protected
  • All
Menu

External module web

Index

Type aliases

HttpRequest

HttpRequest: Request

type representing a raw request.

HttpResponse

HttpResponse: IncomingMessage

type representing a raw response.

Functions

ajax

  • drives an HTTP request against the Relution server.

    Behavior of this method is simplified from most HTTP/AJAX implementations:

    • When the HTTP request succeeds the resulting promise resolves to the response body.
    • In case of a network Error the promise resolves to an HttpError object providing requestUrl but neither statusCode nor statusMessage.
    • In case of HTTP failure the resulting promise is rejected to an HttpError-like object carrying the properties requestUrl, statusCode and statusMessage.
    • If the server responds a JSON, it is parsed and assumed to be an HttpError-like object. The object is augmented by the properties as defined above.
    • Otherwise the body is stored as message of an HttpError object created. Again, the properties above are provided.
    • Finally, in case of HTTP failure with the server not providing any response body, the HttpError message is set to the statusMessage.

    Thus, to differentiate network failures from server-side failures the statusCode of the HttpError rejection is to being used. For deeper inspection provide an [[options.responseCallback]].

    Relution.init({
       serverUrl: 'http://localhost:8080',
       organization: 'myOrga'
    });
    
    let httpOptions: HttpOptions = {method: 'GET', url: 'api/v1/posts'};
    
    //usage as Promise
    Relution.web.ajax(httpOptions)
     .then((resp) => console.log('posts', resp);)
     .catch((e:Relution.web.HttpError) => console.error(e.message, e))
     .finally(() => console.log('loading complete!'));
    
    // as Observable
    Observable.fromPromise(Relution.web.ajax(httpOptions)).subscribe(
     (resp: any) => console.log('posts', resp),
     (e:Relution.web.HttpError) => console.error(e.message, e);,
     () => console.log('loading complete!')
    )
    

    Type parameters

    • T

    Parameters

    • options: HttpOptions

      of request, including target url.

    Returns Promise<T>

    of response body, in case of failure rejects to an HttpError object including requestUrl, statusCode and statusMessage.

clearOfflineLogin

  • deletes stored login response of some server.

    internal

    Not part of public API, for library use only.

    Parameters

    • credentials: Credentials

      allowing to differentiate when multiple logins are used simultaneously, may be null to forget just anything.

    • serverOptions: ServerUrlOptions

      identifying the server.

    Returns Promise<void>

    indicating success or failure.

del

  • del<T>(optionsOrUrl: HttpOptions | string, body?: any): Promise<T>
  • issues an http/ajax DELETE request against the Relution server.

    Please consider this export as an implementation detail of the library and use delete instead.

    see

    head

    see

    get

    see

    put

    see

    post

    see

    patch

    see

    delete

    see

    ajax

    Type parameters

    • T

    Parameters

    • optionsOrUrl: HttpOptions | string

      of request, including target url, or url.

    • Optional body: any

      request body to submit in case optionsOrUrl is a url.

    Returns Promise<T>

    of response body, in case of failure rejects to an Error object including requestUrl, statusCode and statusMessage.

fetchOfflineLogin

  • reads response data from persistent storage.

    When there is no data in persitent store, the operation does NOT fail. In this case the resulting promise resolves to nil instead.

    internal

    Not part of public API, for library use only.

    Parameters

    Returns Promise<LoginResponse>

    read from store, resolves to nil when there is no data, gets rejected when decryption fails.

get

  • get<T>(optionsOrUrl: HttpOptions | string): Promise<T>
  • issues an http/ajax GET request against the Relution server.

    see

    head

    see

    put

    see

    post

    see

    patch

    see

    delete

    see

    ajax

    Type parameters

    • T

    Parameters

    • optionsOrUrl: HttpOptions | string

      of request, including target url, or url.

    Returns Promise<T>

    of response body, in case of failure rejects to an Error object including requestUrl, statusCode and statusMessage.

head

  • head<T>(optionsOrUrl: HttpOptions | string): Promise<T>
  • issues an http/ajax HEAD request against the Relution server.

    see

    get

    see

    put

    see

    post

    see

    patch

    see

    delete

    see

    ajax

    Type parameters

    • T

    Parameters

    • optionsOrUrl: HttpOptions | string

      of request, including target url, or url.

    Returns Promise<T>

    of response body, in case of failure rejects to an Error object including requestUrl, statusCode and statusMessage.

localStorage

  • localStorage(): any
  • localStorage of browser or via require node-localstorage.

    internal

    Not public API, exported for testing purposes only!

    Returns any

login

  • logs into a Relution server.

    Notice, specifying offlineCapable=true in the options will store the login response locally on the device when online and the login succeeded. When offline, the option will reuse the stored response. Data encryption is used guaranteeing both secrecy of login data and verification of the credentials provided.

    example
    
    import * as Relution from 'relution-sdk';
    //config
    Relution.init({
       serverUrl: 'http://localhost:8080'
    });
    
    let credentials = {
       userName: 'myusername',
       password: 'mypassword'
    };
    
    //usage
    
    // Promise
    Relution.web.login(credentials)
     .then((resp) => console.log('resp', resp);)
     .catch((e:Error) => console.error(e.message, e))
     .finally(() => console.log('complete'));
    
    //Observable
    Observable.fromPromise(Relution.web.login(credentials)).subscribe(
     (resp: any) => console.log('resp', resp),
     (e:Error) => console.error(e.message, e);,
     () => console.log('complete')
    )
    

    Parameters

    Returns Promise<LoginResponse>

    of login response.

logout

  • logs out of a Relution server.

    For explicit logouts (trigger by app user pressing a logout button, for example) specifying offlineCapable = true will drop any persisted offline login data for the server logging out of.

    example
    
    Relution.web.logout()
     .then((resp) => console.log('resp', resp);)
     .catch((e:Error) => console.error(e.message, e))
     .finally(() => console.log('bye bye'));
    
    //Observable
    Observable.fromPromise(Relution.web.logout()).subscribe(
     (resp: any) => console.log('resp', resp),
     (e:Error) => console.error(e.message, e);,
     () => console.log('bye bye')
    )
    

    Parameters

    Returns Promise<void>

    of logout response.

patch

  • patch<T>(optionsOrUrl: HttpOptions | string, body?: any): Promise<T>
  • issues an http/ajax PATCH request against the Relution server.

    see

    head

    see

    get

    see

    put

    see

    post

    see

    delete

    see

    ajax

    Type parameters

    • T

    Parameters

    • optionsOrUrl: HttpOptions | string

      of request, including target url, or url.

    • Optional body: any

      request body to submit in case optionsOrUrl is a url.

    Returns Promise<T>

    of response body, in case of failure rejects to an Error object including requestUrl, statusCode and statusMessage.

post

  • post<T>(optionsOrUrl: HttpOptions | string, body?: any): Promise<T>
  • issues an http/ajax POST request against the Relution server.

    see

    head

    see

    get

    see

    put

    see

    patch

    see

    delete

    see

    ajax

    Type parameters

    • T

    Parameters

    • optionsOrUrl: HttpOptions | string

      of request, including target url, or url.

    • Optional body: any

      request body to submit in case optionsOrUrl is a url.

    Returns Promise<T>

    of response body, in case of failure rejects to an Error object including requestUrl, statusCode and statusMessage.

put

  • put<T>(optionsOrUrl: HttpOptions | string, body?: any): Promise<T>
  • issues an http/ajax PUT request against the Relution server.

    see

    head

    see

    get

    see

    post

    see

    patch

    see

    delete

    see

    ajax

    Type parameters

    • T

    Parameters

    • optionsOrUrl: HttpOptions | string

      of request, including target url, or url.

    • Optional body: any

      request body to submit in case optionsOrUrl is a url.

    Returns Promise<T>

    of response body, in case of failure rejects to an Error object including requestUrl, statusCode and statusMessage.

resolveApp

  • computes the basepath of a BaaS application.

    Parameters

    • baseAliasOrNameOrApp: any

      baseAlias of application, may be name when baseAlias is not changed by developer or application metadata object of Relution server.

    • Default value options: ServerUrlOptions = {}

      of server in effect.

    Returns string

    absolute URL of application alias on current server.

resolveServer

  • computes a server url from a given path.

    Parameters

    • path: string

      path to resolve, relative or absolute.

    • Default value options: ServerUrlOptions = {}

      of server in effect.

    Returns string

    absolute URL of server.

resolveUrl

  • computes a url from a given path.

    • absolute URLs are used as is, e.g. http://192.168.0.10:8080/mway/myapp/api/v1/some_endpoint stays as is,
    • machine-relative URLs beginning with / are resolved against the Relution server logged into, so that /gofer/.../rest/...-style URLs work as expected, for example /mway/myapp/api/v1/some_endpoint resolves as above when logged into http://192.168.0.10:8080,
    • context-relative URLs such as api/v1/... are resolved using the Relution server logged in, the uniqueName of the currentOrganization and the application name, for example api/v1/some_endpoint resolves as above when application myapp logged into http://192.168.0.10:8080 using a user of organization mway provided currentOrganization was not changed explicitly to something else.

    Parameters

    • path: string

      path to resolve.

    • Default value options: ServerUrlOptions = {}

      of server in effect.

    Returns string

    absolute URL of path on current server.

storeOfflineLogin

  • writes response data to persistent storage for offline login purposes.

    internal

    Not part of public API, for library use only.

    Parameters

    Returns Promise<LoginResponse>

    indicating success or failure.

Generated using TypeDoc