static-api
A node module that reads a JSON file and generates a static folder structure that matches the JSON to allow data end points for simple apps without the hassle of setting up your own server.
Inspired by the Jekyll approach to static website hosting. You can maintian your 'database' offline then run this script and push the changes to your live site.
How to use
The json file
Create a .json file that strucuture matches your desired API.
my-api.json
The code
Using command line
install static-api using npm
npm install static-api -g
Run in the command line like so
-f example/data -j example/example.json
Where -f is the folder you would like the api to saved to and -j the path to the JSON file containing the structure
Using a node app
Include 'static-api' as a dependency in your package.json and create a file a js file similar to the code below.
var baseData = //load your json file path = staticApi = ; //load the module var dataFolder = path; outputFolder: dataFolder //where the data will be stored object: baseData //the object to create the file structure from;
The result
After running the js file in the command line using: node myapp.js
This should result in a simlar structure to the following
/data/
...../my-api.json
...../artists/
............./artists.json
............./0123/
................../0123.json
................../albums/
........................./albums.json
........................./456/
............................./456.json
............................./tracks/
..................................../tracks.json
..................................../1/
....................................../1.json
..................................../2/
....................................../2.json
............./0743/
....etc..
So now if you hit the following URL from your application /data/artists/0123/albums/456/456.json you will get the following:
You can now quickly produce a static API that you can use with your simple JavaScript app allowing you to focus on doing what you do best: creating awesome web apps or producing amazing prototypes.