Skip to content

REST API for writing and reading self-destructing messages with optional auto-expiry timers using a redis backend.

License

Notifications You must be signed in to change notification settings

stumelius/self-destructing-messages-api

Repository files navigation

Build Status codecov Maintainability Updates

self-destructing-messages-api

REST API for writing and reading self-destructing messages with optional auto-expiry timers using a redis backend.

Usage

First, run redis backend in Docker:

docker run -p 6379:6379 -d redis

Next, start the API server:

serve_seppuku_api.py -e REDIS_HOSTNAME=localhost REDIS_PORT=6379

Send message "foo" with a 600-second auto-expiry timer as a POST request:

curl -sX POST http://localhost:5002/api/v1/seppuku-message?value=foo\&expire=600

The response should look something like this: {"key": "b366fa0e-448c-433f-83e2-5e3b1723f8ab", "expire": 600}. Now, send GET request to read the message:

curl -sX GET http://localhost:5002/api/v1/seppuku-message?key=b366fa0e-448c-433f-83e2-5e3b1723f8ab

The response should be {"value": "foo"}. If you re-send the same GET request, you'll get {} and a status code 400 because the key-message pair does not exist anymore.

Alternatively, you can use tools like jq to parse the POST response and use the extracted key to compose the GET response:

key=$(curl -sX POST http://localhost:5002/api/v1/seppuku-message?value=foo\&expire=600 | jq -r '.key')
curl -sX GET http://localhost:5002/api/v1/seppuku-message?key=$key

About

REST API for writing and reading self-destructing messages with optional auto-expiry timers using a redis backend.

Resources

License

Stars

Watchers

Forks

Packages

No packages published