Skip to content

Repository files navigation

ljs

Little JSON Server is a "build your own" version of the famous JSON Server written in less than 500 lines of C. This is possible by using following libraries:

Build

ljs uses GNU Build System, to build the project simply type:

mkdir _build
cd _build
../configure
make

You can check if everything is fine with:

make check

Usage

ljs has the following usage:

ljs --help
Usage: ljs [OPTION...] [FILE]
ljs -- Little JSON server

  -p, --port=PORT            Server port (default 8080)
  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.

Report bugs to <julien.rouzieres@mac.com>.

Examples:

  • ljs data.json
  • ljs -p 9000 data.json
  • echo '{"foo":[{"id":1,"bar":"baz"}]}' | ljs -p 9000

Routes

Consider following JSON file data.json:

{
  "foo":[
    {
      "id":1,
      "bar":"baz"
    }
  ]
}

Running ljs data.json exposes following routes :

Method Route
GET /foo
GET /foo/:id
POST /foo
PUT /foo/:id
DELETE /foo/:id

For example, to create a new node:

curl -X POST -d '{"id":2,"bar":"baz"}' http://localhost:8080/foo
{"id":2,"bar":"baz"}

Or to update an existing one:

curl -X PUT -d '{"id":2,"baz":"bar"}' http://localhost:8080/foo/2
{"id":2,"baz":"bar"}

Signals

You can send SIGUSR1 to ljs to write changes to input file, typically for an existing ljs PID:

kill -s SIGUSR1 $PID
Writting changes to data.json

About

Little JSON Server

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages