micurs / relax.js

A simple framework to build RESTful web services
MIT License
2 stars 0 forks source link

Add support for cookies #8

Open micurs opened 9 years ago

micurs commented 9 years ago

A resource handler should be able to set a cookie (in its response) and retrieve a cookie (in the incoming message).

micurs commented 9 years ago

To set a cookie:

var cookieSetter = {
  name: 'cookieSetter',
  onGet: function( q, response ) {
    // create a cookie using any cookie library available on node and serialize it as cookieStr
    this.setCookie( cookieStr );
    this.ok(response);
 }
};

To get cookies within the request:

var cookieGetter = {
  name: 'cookieGetter',
  onGet: function( q, response ) {
    // retrieve all the cookies as an unparsed array of string
    var cks: string[] = this.getCookies();
    // parse the cookies with any available cookie library available on node ...
    this.ok(response);
 }
};