A simple and easy to use Node.js component for making Nebri backend requests.
This app is intended for use with a Nebri instance. Visit https://nebrios.com to sign up for free!
This app can be installed via npm: ``` npm install nebrie/nodejs-nebri --save ``` - including --save at the end will install this component and add it as a dependency in your app's package.json The NebriClient must be initialized before you can use the available functions. ``` var nebri = require('nodejs-nebri'); var nebriclient = new nebri.NebriClient('instance_name'); ``` - instance name is your Nebri instance name. i.e. https://instance_name.nebrios.com api_request - api_module: the name of the api module stored on your Nebri instance - view_name: the name of the target function contained in the given api module - method: the desired HTTP request method - payload: an object containing params and values, can be an empty object - callback (optional): the function to execute after a successful api request. this callback will receive all data included in your view's response - error_callback (optional): the function to execute after an unsuccessful api request. ``` var nebri = require('nodejs-nebri'); var nebriclient = new nebri.NebriClient('instance_name'); nebriclient.api_request('greeting_api', 'start_greeting', 'GET', {'greeting': 'hello'}); ``` - in the above example, we don't send a callback or error callback function - this is not recommended as there isn't a way to see what data is being sent with a given responsevar nebri = require('nodejs-nebri');
var nebriclient = new nebri.NebriClient('instance_name');
nebriclient.api_request('greeting_api', 'start_greeting', 'GET', {'greeting': 'hello'}, function(data){
console.log(data); //outputs {"identifier": "02fe4cee4d484b9bae044bd640bce76"}
});
To make your code easier to read, we recommend defining a function first and passing the name as a parameter.
var nebri = require('nodejs-nebri');
var nebriclient = new nebri.NebriClient('instance_name');
var callback = function(data){
console.log(data); //outputs {"identifier": "02fe4cee4d484b9bae044bd640bce76"}
};
nebriclient.api_request('greeting_api', 'start_greeting', 'GET', {'greeting': 'hello'}, callback);
var nebri = require('nodejs-nebri');
var nebriclient = new nebri.NebriClient('instance_name');
var callback = function(data){
console.log(data);
};
var error_callback = function(data){
console.log(data); //outputs Bad Request Response because greeting isn't supported
};
nebriclient.api_request('greeting_api', 'start_greeting', 'GET', {'greeting': 'hi'}, callback, error_callback);