Skip to content
Jayesh Choudhary edited this page Jan 7, 2020 · 12 revisions

Classes

Api

Class representing the client api.

External

DB

The DB Client Interface.

Realtime

The Realtime Client Interface.

FileStore

The FileStore Client Interface.

Api

Class representing the client api.

Kind: global class

new Api(projectId, url)

Create an instance of the Client API.

Param Type Default Description
projectId string The Project Id.
url string "/" Base url of space-cloud server.

Example

import { API } from 'space-api';

const api = new API('my-project', 'http://localhost:4122');

api.setToken(token)

Initialse the Client Api with the JWT token

Kind: instance method of Api

Param Type Description
token string The signed JWT token received from the server on successful authentication.

api.setProjectId(projectId)

Set the new Project Id

Kind: instance method of Api

Param Type Description
projectId string The Project Id.

api.Mongo() ⇒ DB

Deprecated

Returns a Mongo DB client instance

Kind: instance method of Api
Returns: DB - DB client instance

api.Postgres() ⇒ DB

Deprecated

Returns a Postgres DB client instance

Kind: instance method of Api
Returns: DB - DB client instance

api.MySQL() ⇒ DB

Deprecated

Returns a MySQL Db client instance

Kind: instance method of Api
Returns: DB - Db client instance

api.DB(db) ⇒ DB

Returns a DB client instance

Kind: instance method of Api
Returns: DB - DB client instance

Param Type Description
db string The alias name of the database

api.call(service, endpoint, params, [timeout]) ⇒ Promise

Calls an endpoint from the remote service

Kind: instance method of Api
Returns: Promise - Returns a promise

Param Type Default Description
service string The name of service
endpoint string The name of endpoint to be called
params Object The params to be sent to the remote service
[timeout] string 5000 Timeout in milliseconds

Example

api.call('my_service', 'my_endpoint', { msg: 'Remote services are awesome!' }, 1000)
.then(res => {
  if (res.status === 200) {
    // res.data contains the response given by the function
    console.log('Response:', res.data);
    return;
  }
}).catch(ex => {
  // Exception occured while processing request
});

api.FileStore() ⇒ FileStore

Returns a FileStore client instance

Kind: instance method of Api
Returns: FileStore - FileStore client instance

DB

The DB Client Interface.

Kind: global external
See: https://github.com/spaceuptech/space-api-js/wiki/DB

Realtime

The Realtime Client Interface.

Kind: global external
See: https://github.com/spaceuptech/space-api-js/wiki/Realtime

FileStore

The FileStore Client Interface.

Kind: global external
See: https://github.com/spaceuptech/space-api-js/wiki/FileStore