keva is a key:value datastore with http json interface.
build it:
go mod tidy
go build
run it the normal way:
./keva
if you're fancy:
./keva --port=:8080 --savepath=mydata.json --saveinterval=10s
-
--port
(optional): define the server port.- default:
:8080
- default:
-
--savepath
(optional): define the path to save the key-value store data.- default:
data.json
- default:
-
--saveinterval
(optional): define the interval to automatically save data.- default:
5s
- default:
to better understand the usage of keva
, here's a series of curl
commands to try it out on your own:
curl -x post http://localhost:8080/store/demokey -h "content-type: application/json" -d '{"value": "demo value"}'
output:
ok
curl -x get http://localhost:8080/store/demokey
output:
"demo value"
curl -x delete http://localhost:8080/store/demokey
output:
ok
curl -x get http://localhost:8080/store/demokey
output:
key not found
curl -x get http://localhost:8080/health
output:
healthy
description: retrieve a value by the given key.
parameters:
key
: the key associated with the stored value.
response:
200 ok
: value retrieved successfully. it returns the stored value in json format.404 not found
: key not found.
example:
curl -x get http://localhost:8080/store/examplekey
description: store a value associated with the given key.
parameters:
key
: the key to store the value with.
request body: json object containing the value to store.
value
(string): the value to be stored.
response:
201 created
: key-value set successfully.400 bad request
: no value provided or bad request format.
example:
curl -x post http://localhost:8080/store/examplekey -h "content-type: application/json" -d '{"value": "this is an example value"}'
description: delete the value associated with the given key.
parameters:
key
: the key of the value to delete.
response:
200 ok
: key deleted successfully.404 not found
: key not found.
example:
curl -x delete http://localhost:8080/store/examplekey
description: health check endpoint.
response:
200 ok
: healthy.
example:
curl -x get http://localhost:8080/health
the api uses conventional http response codes to indicate the success or failure of an api request.
200 ok
: the request was successful.201 created
: the request was successful and a resource was created.400 bad request
: the request could not be understood or was missing required parameters.404 not found
: resource not found. this can be used when a specific key does not exist in the store.405 method not allowed
: the http method used is not valid for the specific endpoint.
- the keyvalue store is thread-safe, using mutexes to ensure that concurrent requests do not conflict.
- the data is periodically saved to a file (default path is
data.json
) at a set interval (default is every 5 seconds). this behavior ensures that the data remains persistent even if the application restarts.
mit license 2023 donuts-are-good, for more info see license.md