The Mixnode Node.js SDK allows you to easily integrate the Mixnode REST APIs into your Node.js application.
- Node.js version 4 and above.
- A Mixnode API key from a registered user on the Mixnode portal.
npm install mixnode-node-sdk --save
Follow this tutorial to see a step-by-step guide and examples of how to use the Mixnode Node.js SDK.
- Create an account on Mixnode.
- If already registered, then login and navigate to api key page.
- Dashboard -> Choose API from left menu -> Note the API key.
- Or, directly navigate to https://www.mixnode.com/account/api to find your API key.
This SDK comes with basic authentication over HTTPS which requires you to pass your Mixnode API key using a config file or as a json object during SQL client instantiation.
This type of token is given directly to the application.
var Mixnode = require('mixnode-node-sdk');
// Create an instance of the Mixnode SQL Client
const SQLClient = new Mixnode.SQLClient({
api_key: 'XXXXXX' // add your API KEY here; available at https://www.mixnode.com/account/api
});
Note that api_key
can also be passed as a JSON object in a config file to avoid specifying the key in the code.
Please see Examples
const Mixnode = require('./../src/index');
const config = require('./config.js');
const SQLClient = new Mixnode.SQLClient(config);
// Gets 10 urls and their title from homepages table
SQLClient.execute('SELECT url, title from homepages LIMIT 10')
.then((response) => {
console.log(response);
}).catch((err) => {
console.log(err);
});
SQLClient.execute
is an asynchronous operation which returns a promise
object either resolving as a response or error which could then be obtained using then
or catch
statements.
SQLClient.execute can accept upto four parameters : query, vars (optional), inputLimit (optional), timeout (optional). Please see various Examples for usage details.
SQLClient.execute(query).then((response) => {
// Do somethere here with the response
}).catch((err) => {
// Do something with the exception
});
SQLClient.execute(query, vars).then((response) => {
// Do somethere here with the response
}).catch((err) => {
// Do something with the exception
});
SQLClient.execute(query, vars, inputLimit).then((response) => {
// Do somethere here with the response
}).catch((err) => {
// Do something with the exception
});
SQLClient.execute(query, vars, timeout).then((response) => {
// Do somethere here with the response
}).catch((err) => {
// Do something with the exception
});
SQLClient.execute(query, vars, inputLimit, timeout).then((response) => {
// Do somethere here with the response
}).catch((err) => {
// Do something with the exception
});
- Turning on the debug mode logs the HTTP requests being sent to the Mixnode API.
- This is useful to verify if the queries being sent are correct.
- This is useful to verify if the execution is in progress.
/* Setting debug to true logs the state of the application.
Do not use this in production.
*/
Mixnode.setDebug(true);
SQLClient.execute(query).then((response) => {
// Do somethere here with the response
}).catch((error) => {
// Do something with the exception
});
error.code
=> Mixnode specified error code.error.statusCode
=> Http status code of the error.error.message
=> Message received from backend or due to exception caused in SDK code.error.name
=> SDK specified generic name of the error.error.status
=> Status of the query at the time of the error.error.stack
=> Stack trace of the error
You can get the full documentation for the API on the Mixnode SQL API reference