API Reference: Net.Http

Http module is used for sending http requests.

RESTful Services

"request()" method of Http provides making a REST request. It takes an argument named method. You can specify the method by setting this parameter.

Handling Response of a Request

Each http method has a "onLoad" callback and a "onError" callback. You can handle error and response using these callbacks.

const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const ImageView = require('sf-core/ui/imageview');
const FlexLayout = require('sf-core/ui/flexlayout');
const Http = require("sf-core/net/http");
var PageHttp = extend(Page)(
function PageHttp(_super) {
_super(this, {
onShow: function() {
Application.statusBar.visible = false;
this.headerBar.visible = false;
var sessionManager = new Http();
var request = sessionManager.requestImage({
url : '',
onLoad : function(e) {
// Image loaded.
myImageView.image = e.image;
onError : function(e) {
// Http request image failed.
var myImageView = new ImageView({
width: 100,
height: 100,
alignSelf: FlexLayout.AlignSelf.CENTER,
imageFillType: ImageView.FillType.STRETCH
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
module.exports = PageHttp;

Consider Http Behavior

If the given url is invalid, Http request does not fire onError callback.

Android Permissions

You have to add following permission to your AndroidManifest.xml file before publishing your project.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Also you can check Application Permission Management for other permissions.


If you try to make a request when no network connection, onError callback triggers.

Also, onError callbacks triggers when timeout.

If you pass body parameter with http methods that do not require body parameter, iOS throws an exception, but Android ignores the body parameter and works fine.