HTTP server that can persistently store and retrieve key-value pairs. Exposes a resftull API to interact with stored values and to store new key-value pairs.
-
Create a interface for storage
-
Setup some unit tests
-
Refactor everything regarding err handling
All configuration is specified in config.yaml
server:
port: "8090"
host: "localhost"
entry point resides under cmd/main/main.go, you can chose to run directly towards main.go
go run cmd/main/main.go
or to build a binary
go build cmd/main/main.go
./main.go
or using any containerization tool towards Containerfile, (example with podman)
podman build .
podman run -it <CONTAINER-ID>
Configure the host and port you wish to run the server on. Below examplees assumes localhost and 8090.
Ensures basic functionality and can be used to test connectivity. Returns a 200 OK response on request.
Call:
curl localhost:8090/api/status
Response:
{"data":"\n","status":"200 OK\n"}
Store a key-value pair. Asumes a data payload with key and value, see data.json below as example. Returns a 200 OK response and the key-value pair after successfull storeage.
Call:
curl -X POST -H "Content-Type: application/json" -d @data.json http://localhost:8090/api/some_key
data.json:
{ "value" : "some_value" }
Response:
{"some_key":"some_value","status":"200 OK"}
List the value for a given key. Returns a 200 OK response and the value of the corresponding key.
Call:
curl localhost:8090/api/list/some_key
Response:
{"data":"some_value","status":"200 OK"}