dig1t / express-restful-store

restsession - Store your express-session in a RESTful way

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Express.js RESTful Store

This is an ESM-only module, it must be imported using the import declaration or the import() syntax. It cannot be required from a CommonJS module.

Usage in express

Example:

import express from 'express'
import session from 'express-session'
import RestStore from './index.js'

const app = express()

app.use(session({
  secret: 'xxxxxxxxxxxxxxxx',
  store: new RestStore('http://127.0.0.1/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 exist, the API should respond with a 404 error code.

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.

About

restsession - Store your express-session in a RESTful way


Languages

Language:JavaScript 100.0%