User login

Does the Session Host Object support looping?

Forums :

Hi,

I'm trying to extend the REST sample to provide a "list" capability by creating a new function listWeather() whose httpMethod is "GET" and whose httpLocation is "weather", not "weather/{city}".

Within the function body, I need to loop through all objects held in the session object, but it appears from the API for the session host object that only put() and get() methods are supported. It would be good to have size() and getKeys() methods as well.

Any suggestions for a workaround?

Regards,

Ganesh Prasad

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Interesting point

Interesting point Ganesh,

The session host object in its present form doesn't support looping. I will add size() and getKeys() to it.

As a workaround, you can try maintaining a keystore in session as well. As a javascript array perhaps? This array should contain all the keys of the objects you want to loop through later.  When storing something in session, you will have to update this array as well. Not very elegant, but serves the purpose.

Hope this helps,

Tyrell

 

 

 

 

Thanks

Tyrell, thanks.

Yeah, it's not elegant, but it works (attached for your viewing pleasure ;-).

Regards,

Ganesh

AttachmentSize
RESTSample_js.txt3.48 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.