New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rest-sessions

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-sessions

A REST interface for redis-sessions

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-62.5%
Maintainers
1
Weekly downloads
 
Created
Source

REST Sessions

A REST interface to handle and share sessions between different app server platforms. Based on redis-sessions.

Installation

npm install rest-sessions

Run npm install to install the dependencies.

For the test make sure Redis runs locally and run npm test

Methods

POST /:app/create/:id

Create a session for :app and user :id

Parameters:

  • ip The IP of the user
  • ttl optional (default: 7200) The timeout for the session in seconds

Example:

POST /mywebapp/create/user123?ip=192.168.99.22&ttl=86400

Response:

{"token": "KrxwdpUjoTQcYmMISjQE2C4drmXMhn5w2gX0388UySdPYoEJkPa74nhZhg3iaj7w"}

Note: You should save this token in a cookie and use it in subsequent requests to identify the user via GET /:app/get/:token

GET /:app/get/:token

Get a session for :app and :token

Example:

GET /mywebapp/get/KrxwdpUjoTQcYmMISjQE2C4drmXMhn5w2gX0388UySdPYoEJkPa74nhZhg3iaj7w

Response:

{
    "id": "user123",
    "r": 1,  // The read counter for this session
    "w": 1,  // The write counter for this session
    "ttl": 86400,
    "idle": 273,  // The idle time since the previous request
    "ip": "192.168.99.22"
}

POST /:app/set/:token

Set some additional parameters for this session via a simple JSON object supplied via the POST body.

Example 1:

POST /mywebapp/set/KrxwdpUjoTQcYmMISjQE2C4drmXMhn5w2gX0388UySdPYoEJkPa74nhZhg3iaj7w
Content-Type: application/json

{
	"name": "Peter Smith",
	"unread_msgs": 12
}

Response:

{
    "id": "user123",
    "r": 1,
    "w": 2,
    "ttl": 86400,
    "idle": 211,
    "ip": "192.168.99.22",
    "d": {
        "name": "Peter Smith",
        "unread_msgs": 12,
        "age": 46
    }
}

Example 2:

  • To remove a key set it to null
  • If you omit a key it will stay untouched
POST /mywebapp/set/KrxwdpUjoTQcYmMISjQE2C4drmXMhn5w2gX0388UySdPYoEJkPa74nhZhg3iaj7w
Content-Type: application/json

{
	"name": "Bruce Dickinson",
	"unread_msgs": null,
	"job": "making gold records"
}

Response:

Note that the unread_msgs field was removed and age was not touched.

{
    "id": "user123",
    "r": 1,
    "w": 3,
    "ttl": 86400,
    "idle": 17,
    "ip": "192.168.99.22",
    "d": {
        "name": "Bruce Dickinson",
        "age": 46,
        "job": "making gold records"
    }
}

GET /:app/activity

Get the number of active unique users (not sessions!) within the last n seconds

Parameters:

  • dt Delta time. Amount of seconds to check (e.g. 600 for the last 10 min.)

Get a session for :app and :token

Example:

GET /mywebapp/activity?dt=600

Response:

{"activity": 1}

DELETE /:app/kill/:token

Kill a single session of an app.

Example:

DELETE /mywebapp/kill/KrxwdpUjoTQcYmMISjQE2C4drmXMhn5w2gX0388UySdPYoEJkPa74nhZhg3iaj7w

Response:

{"kill": 1}

DELETE /:app/killsoid/:id

A single unique user id might have multiple sessions on different devices and/or browsers. This methods kills all sessions of an id.

Example:

DELETE /mywebapp/killsoid/user123

Response:

{"kill": 3}

DELETE /:app/killall

Kills all sessions of an app.

Example:

DELETE /mywebapp/killall

Response:

{"kill": 42}

Keywords

FAQs

Package last updated on 02 May 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc