Skip to content

zlumer/json-tree-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Tree Server

Serves JSON over HTTP similar to Firebase Realtime Database HTTP.

Usage

NPM

npx json-tree-server ./source

Launches an HTTP server that serves nested JSON structures from the provided ./source directory.

Extra arguments:

  • -p {PORT}: port to listen on (default: 3000)
  • --enable-json-postfix: all queries must end with '.json' (for compatibility with Firebase RTDB)

Example directory structure:

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

Why?

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published