Skip to content

raboof/leveldb-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

leveldb-http

This tiny project takes the multilevel-http HTTP API for LevelDB and adds:

Starting

$ export DB_USER=foo
$ export DB_PASS=bar
$ ./app.js

API

See multilevel-http for the generic LevelDB API.

This project adds 2 additional endpoints:

GET /latest/:prefix

Get the value associated with the largest key starting with this prefix, assuming ASCII keys.

$ http get http://pi:5000/latest/temperature
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Type,WWW-Authenticate
Connection: keep-alive
Content-Type: application/json
Date: Mon, 04 Aug 2014 18:21:12 GMT
Transfer-Encoding: chunked
X-Powered-By: Express

{
    "timestamp": 1407176469778, 
    "value": 24.812
}

GET /stream/:prefix

Get an EventSource stream with new values for this prefix.

$ http --stream get http://pi:5000/stream/temperature 
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Type,WWW-Authenticate
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream
Date: Wed, 06 Aug 2014 18:38:17 GMT
Transfer-Encoding: chunked
X-Powered-By: Express


id: temperature-1407350298138
data: {"timestamp":1407350298138,"value":24.062}

id: temperature-1407350304219
data: {"timestamp":1407350304219,"value":24.000}

^C

By default this shows the latest value and streams indefinitely from there, but the 'gt' and 'lt' parameters can be used to include more or less data.

History

This small app was written to serve as a lightweight time-series db for my 'web thermostat' project. I'm using a Raspberry Pi to monitor the current temperature, provide a web UI to set the desired temperature, and control my central heating based on that.

The components mentioned above made it quite easy to put this together. The only downside that I've run into so far is that due to LevelDB's single-process nature, it's not possible to keep the POST API up while restarting the read-only part of the app. A minor drawback.

About

Expose LevelDB through a HTTP interface

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published