Options
All
  • Public
  • Public/Protected
  • All
Menu

Module u-http

The u-http module offers a Request class that lets you setup HTTP requests easy in your app.

In this example, we create an action that you can attach to the "On Press" event of a button. You also need to supply the action with a Text component.

When the action is triggered, it sends a HTTP request to fetch a list of Bitcoin trade data. The response is handled in the success callback, by displaying the data in the Text component. Errors are handled in the error callback handler.

var uHttp = require('u-http');
var Request = uHttp.Request;
var uActions = require('u-actions');
var Action = uAction.Action;

new Action('Get Bitcoin Trades', getBitcoinTrades)
.addParameter('Output', uActions.ParamType.TEXT)
.register();
function getBitcoinTrades(outputTxt) {
new Request('https://bitnz.com/api/0/trades')
.addParameter('since_date', '1448971200')
.onSuccess(getBitcoinTradesSuccess, [outputTxt])
.onError(getBitcoinTradesError)
.get();
}

function getBitcoinTradesSuccess(result, outputTxt) {
var jsonResult = JSON.parse(result);
var formatterResult = JSON.stringify(jsonResult, null, '\t');
outputTxt.text = formatterResult;
}

function getBitcoinTradesError(error) {
console.log(error);
}

Index

Classes

Interfaces

Functions

Functions

  • useLegacyCallbacks(legacyCallbacks: boolean): void
  • Set legacy mode for http callbacks, so callbacks use the old syntax.

    Parameters

    • legacyCallbacks: boolean

      Set legacy callbacks on or off.

    Returns void