jasonkneen / RESTe

A simple JavaScript REST / API helper for Titanium

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add the possibility to access HttpClient object inside RESTe

cubico opened this issue · comments

commented

I need send cookies to mantain session opened. In first call the server send me a cookie and I must sending to the server the same "Cookie" header for prevent generate many sessions. I have added a simple method after create the HTTPClient object.

(...)
var http = Ti.Network.createHTTPClient();

// simple method to access http
reste.getHTTPClient = function(){
  return http;
}
(...)

After has created the session of backend and the response headers are sended to the client you access to the cookie with this call: api.getHTTPClient().getResponseHeader('set-cookie')

PR for this?

Cookie header? If you need to set request headers that is supported already. Reste also supports cookie based sessions where the server saves a cookies and the uses that to auth the session transparent to reste. I user cookie auth on a project and it worked fine.

Sounds like what you're as doing for is setCookie and getCookie.

commented

Maybe. :)

In the validation session is created and the backend server (SailsJS) returns the cookie (I save the sessions in Redis). In this response I also generate a token (JWT) that happened on subsequent calls, but if I do not add the same cookie, another session is created and so I need to take this value after the validation.

I use "setRequestHeaders" to send the cookie and the token.

By saving the token and the cookie in Ti.App.Properties, when I close the app and reopen it, Reste uses the same session already validated by the user and does not generate more sessions.

I do not know if this is the best way to do this ..
Thanks for your quick answer!