Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

example of using session

  • Loading branch information...
commit c5ce6442db9c1cf2674c1d3cdba20dc42d3e0cf0 1 parent a1f6859
@nrstott authored
Showing with 31 additions and 0 deletions.
  1. +31 −0
@@ -119,6 +119,37 @@ with `app.use`. To start the application, use the `start` method.
+## Using Session
+The session middleware can be included individually with `app.use(bogart.middleware.session)` or
+by using batteries `app.use(bogart.batteries)` which includes a default stack of JSGI middleware.
+A `session` function will be available on the request object passed to your route handlers. This
+function follows the jQuery style of arity determining if it is getting or setting a key/value pair.
+A call to session with one argument is a get to the value of the key referenced by the argument.
+ req.session('name'); // => value associated with 'name'
+A call to session with two arguments is a set.
+ req.session('name', 'Nathan'); // sets the value of 'name' to 'Nathan'
+### Contrived Example
+A set of two routes that use session:
+ router.get('/:name', function(req) {
+ req.session('name',;
+ return bogart.redirect('/');
+ });
+ router.get('/', function(req) {
+ return bogart.html('Hello ' +req.session('name'));
+ });
+Visiting '/:name' ('/Nathan', '/Bob', etc...) will set a session key that will
+be displayed by the root route '/', after the redirect.
## Running the Examples
In the 'examples' directory of the cloned source, there are several examples of bogart applications.

0 comments on commit c5ce644

Please sign in to comment.
Something went wrong with that request. Please try again.