Skip to content

Javascript client

Pedro Furió edited this page Nov 25, 2016 · 1 revision

The javascript client that can query Opencga webservices can be found in the jsorolla repository (https://github.com/opencb/jsorolla) in the next-v2.0.0 branch in https://github.com/opencb/jsorolla/tree/next-v2.0.0/src/lib/clients.

An example of how to start using opencga client can be found here.

Opencga client is divided into two separate classes OpenCGAClient and OpenCGAClientConfig. OpenCGAClient receives an instance of OpenCGAClientConfig in order to initialize everything. After that, doing queries is really easy:

`

Initialize

opencgaClientConfig = new OpenCGAClientConfig(host, version); opencgaClient = new OpenCGAClient(opencgaClientConfig); `

Query users opencgaClient.users() will return the [https://github.com/opencb/jsorolla/blob/next- v2.0.0/src/lib/clients/opencga-client.js#L244](user client) containing the following methods:

  • create
  • login
  • logout
  • changeEmail
  • update
  • ...

In order to login, the command line to be run will be something like:

opencgaClient.users().login(userId, password);

All the methods of the OpenCGAClient will return a promise (see https://developers.google.com/web/fundamentals/getting-started/primers/promises). Basically, the way to work with this will be something like:

opencgaClient.users().login(userId, password).then(function(response) { console.log(response); }).catch(function(response) { console.log("Error response:" + response); });

Clone this wiki locally