JSON Tree REST service. Access JSON structure with HTTP path parameters as keys/indices to the JSON.
Refer to the Medium blog post, Emulate the Firebase Realtime Database API with Golang, Postgres, and Websockets, which walks through the process of creating this project.
# start services
$ make up
# rebuild images
$ make rebuild
# build images
$ make build
# stop containers and destroy them
$ make down
# stop containers
$ make stop
# remove images
$ make remove
# clean up; stop containers remove images and volumes
$ make clean
# create tree for new project
$ curl -s -X POST -d '{"age": 25, "job": {"title": "clerk"}, "name": "bob", "friends": ["one", "two"]}' localhost:5001/api/mydb | jq "."
{}
# retrieve full tree
$ curl -s localhost:5001/api/mydb/ | jq "."
{
"age": 25,
"friends": [
"one",
"two"
],
"job": {
"title": "clerk"
},
"name": "bob"
}
# retrieve individual keys
$ curl -s localhost:5001/api/mydb/friends | jq "."
[
"one",
"two"
]
# or by index of array
$ curl -s localhost:5001/api/mydb/friends/1 | jq "."
"two"
$ curl -s localhost:5001/api/mydb/job/title | jq "."
"clerk"
$ curl -s -X POST -d '4' localhost:5001/api/mydb/job/years | jq "."
{}
$ curl -s localhost:5001/api/mydb/ | jq "."
{
"age": 25,
"friends": [
"one",
"two"
],
"job": {
"title": "clerk",
"years": 4
},
"name": "bob"
}
$ curl -s -X PUT -d '{"title": "Engineer", "years": 1}' localhost:5001/api/mydb/job | jq "."
{}
$ curl -s localhost:5001/api/mydb/ | jq "."
{
"age": 25,
"friends": [
"one",
"two"
],
"job": {
"title": "Engineer",
"years": 1
},
"name": "bob"
}
$ curl -s -X DELETE localhost:5001/api/mydb/job | jq "."
{}
$ curl -s localhost:5001/api/mydb/ | jq "."
{
"age": 25,
"friends": [
"one",
"two"
],
"name": "bob"
}
http://jsfiddle.net/anothernick/hcax2gvk/
A JSFiddle prototype which initially displays the JSON Object returned from an HTTP request. The Object is then updated and re-rendered when updates are made to the object (listens on a websocket).
- Websocket work basically taken from gorilla/websocket/chat example
- Tagging action by github-action-tag
MIT Copyright (c) 2019 Nick Sjostrom