Page 1 of 1

Passing a global scope variable into service request header

Posted: Sun Mar 04, 2018 5:21 pm
by Alan Smith

I'm trying to pass a global scope variable into a service header, but I'm not sure on the syntax for this?

I am using an Ionic server code POST request, and I am trying to pass a token via the Authorization header. I cannot seem to use a $scope variable.

The variable on my index page is: auth.

The variable on the model is authtoken

So, this is my sever code:

var url = "URL";

var XHRResponse = XHR2.send("POST", url, {
"headers": {
"Authorization": $scope.auth.token,
},
"body": ""
});

Apperyio.response.success(XHRResponse.body, "application/json");

What is the correct syntax for adding the global variable to the server code request header?


Passing a global scope variable into service request header

Posted: Mon Mar 05, 2018 3:03 pm
by Serhii Kulibaba

Hello Alan,

Do you use this code in the Server Code or in the application?
XHR2, Apperyio.response.success - samples from the Server Code
$scope.auth.token - from the Ionic app

So it seems you've mixed up them.


Passing a global scope variable into service request header

Posted: Mon Mar 05, 2018 3:21 pm
by Alan Smith

Hi Serhii

I have a global variable that I need to send via server code. I have an auth token, saved as a global variable.

How do i send this via server code to the service in the header?


Passing a global scope variable into service request header

Posted: Tue Mar 06, 2018 6:51 am
by Serhii Kulibaba

The global variable is global only in the application, so it is not available in other applications neither in Server Codes.

Please send it as a parameter to the server code and read it there with the code:
https://docs.appery.io/reference#serv...
prevar token = request.get();/pre