All Projects → anothrNick → json-tree-service

anothrNick / json-tree-service

Licence: MIT License
JSON Tree web service. Access JSON structure with HTTP path parameters as keys/indices to the JSON.

Programming Languages

go
31211 projects - #10 most used programming language
HTML
75241 projects
Dockerfile
14818 projects
Makefile
30231 projects
TSQL
950 projects

json-tree-service

JSON Tree REST service. Access JSON structure with HTTP path parameters as keys/indices to the JSON.

Build Status Stable Version

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.

medium

Run Locally

# 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

Make HTTP requests

# 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"

Add key

$ 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"
}

Update key

$ 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"
}

Delete key

$ curl -s -X DELETE localhost:5001/api/mydb/job | jq "."
{}
$ curl -s localhost:5001/api/mydb/ | jq "."
{
  "age": 25,
  "friends": [
    "one",
    "two"
  ],
  "name": "bob"
}

Websocket UI updates prototype

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).

Credit

License

MIT Copyright (c) 2019 Nick Sjostrom

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].