Session
The session resource can be used to store data in a session object and retrieve them for later use. Each login is associated with a session object in the M/Monit server.
Available methods:
POST |
/api/2/session/put | Store a value in session |
GET POST |
/api/2/session/get | Get value from session |
POST |
/api/2/session/delete | Delete a session value |
POST |
/api/2/session/invalidate | Invalidate the session |
put
Add or update the session attribute identified by key (several key=value pairs can be used to add/update multiple attributes at once). If a named attribute already exist, its old value is replaced.
Arguments
| <key=value> | string | required | The key attribute defines the key used to store the data in the session with the specified value |
curl -b ~/.mmonit/cookie \
-d "myvar1=hello&myvar2=world" \
http://127.0.0.1:8080/api/2/session/put
The session is meant for small values, such as a page’s settings, and keeps them in memory while it lasts. A request can carry at most 16 KB of form data, and a key can be at most 247 bytes long. M/Monit stores the sessions in its database when it stops and loads them at start if saveSessions is set in server.xml, as it is by default. With MySQL, a session is stored only if its data, keys and values together with M/Monit’s own, fits in 64 KB.
get
Returns the session attribute matching the key argument (key can be used multiple times). If no keys are specified, all stored attributes in the session are returned.
Arguments
| key | string | optional | The key used to store the data in the session |
curl -b ~/.mmonit/cookie \
-d "key=myvar1&key=myvar2" \
http://127.0.0.1:8080/api/2/session/get
Output
| <key> | The session attribute key value |
{
"myvar1": "hello",
"myvar2": "world"
}
delete
Delete session attributes matching key. If no keys were specified, delete all stored attributes (key can be used multiple times).
Arguments
| key | string | required | The key of the session attribute to delete |
curl -b ~/.mmonit/cookie \
-d "key=myvar1&key=myvar2" \
http://127.0.0.1:8080/api/2/session/delete
invalidate
Invalidates session and unbinds any objects bound to it. This will logout from the M/Monit server because a login is associated with a session object.
curl -b ~/.mmonit/cookie \
-X POST \
http://127.0.0.1:8080/api/2/session/invalidate