/restsession

restsession - Store your express-session in a RESTful way

Primary LanguageJavaScript

restsession

NPM Version NPM Downloads

Usage in express

Example:

import express from 'express'
import session from 'express-session'
import restsession from 'restsession'

const app = express()
const HTTPStore = restsession(session)

app.use(session({
  secret: 'Kgqnq5YsquMjEZd3TX',
  store: new HTTPStore('http://127.0.0.1:1200/sessions'),
  cookie: {
    maxAge: 24 * 60 * 60 * 1000,
    httpOnly: true,
    secure: false
  },
  saveUninitialized: false,
  resave: false
}))

RESTful API Specification (endpoint)

Get list of all Sessions


Request:

GET /

Response:

[
  {
    "key": "value"
  },
  ... sessions
]

Remove everything


Request:

DELETE /

Reponse:

{
  "status": "OK"
}

Get one Session


GET /{sid}

Response:

{
  "key": "value"
}

If the session doesn't exists, The API should throw a HTTP 404 Not Found

Delete one Session


DELETE /{sid}

Reponse:

{
  "status": "OK"
}

Add one Session


Request:

POST /{sid}

{
  "key": "value"
}

Response:

{
  "key": "value"
}

This can also be used in conjuction with the ?ping URL parameter. Then the API is able to update any existing expire times of the session if any. If the session with {sid} already exists, the API should update that one.