Serves JSON over HTTP similar to Firebase Realtime Database HTTP.
npx json-tree-server ./source
Launches an HTTP server that serves nested JSON structures from the provided ./source
directory.
-p {PORT}
: port to listen on (default:3000
)--enable-json-postfix
: all queries must end with '.json' (for compatibility with Firebase RTDB)
source
|-- api.json
|-- configs
|-- extra.json
+-- main.json
// api.json:
{
"v": "0.1",
"nested": {
"object": true
}
}
// configs/extra.json
{
"array": [
{"name": "element"},
false
]
}
Now you can make HTTP requests to server:
// GET /api
{"v":"0.1","nested":{"object":true}}
// GET /api/nested
{"object":true}
// GET /api/nested/object
true
// GET /
{"api":{"v":"0.1","nested":{"object":true}},"configs":{"extra":{"array":[{"name":"object"},false]}}}
// Use number indexes to fetch array elements:
// GET /configs/extra/array/0
{"name":"element"}
// GET /configs/extra/array/1
false
It's common to have multiple JSON files for different kinds of configuration.
json-tree-server
helps you maintain these files and query them similar to regular REST APIs.