Git Product home page Git Product logo

docker-json-server's Introduction

docker-json-server

JSON Server provides REST API mocking based on plain JSON. This is a docker image that eases setup.

Usage

This docker image is available as a trusted build on the docker index, so there's no setup required. Using this image for the first time will start a download automatically. Further runs will be immediate, as the image will be cached locally.

The recommended way to run this container looks like this:

$ docker run -d -p 80:80 -v /home/user/articles.json:/data/db.json clue/json-server

The above example exposes the JSON Server REST API on port 80, so that you can now browse to:

http://localhost/

This is a rather common setup following docker's conventions:

  • -d will run a detached instance in the background
  • -p {OutsidePort}:80 will bind the webserver to the given outside port
  • -v {AbsolutePathToJsonFile}:/data/db.json should be passed to mount the given JSON file into the container
  • clue/json-server the name of this docker image

Help

You can supply any number of JSON Server arguments that will be passed through unmodified.

$ docker run -it --rm clue/json-server --help

JSON source

If you mount a file to /data/db.json (as in the above example), it will automatically be used as the plain JSON data source file.

A sample file could look like this:

{
  "posts": [
    { "id": 1, "body": "foo" },
    { "id": 2, "body": "bar" }
  ],
  "comments": [
    { "id": 1, "body": "baz", "postId": 1 },
    { "id": 2, "body": "qux", "postId": 2 }
  ]
}

JS seed file

If you mount a file to /data/file.js, it will automatically be used as a JS seed file.

JSON Server expects JS files to export a function that returns an object. Seed files are useful if you need to programmaticaly create a lot of data.

A sample file could look like this:

module.exports = function() {
  var data = {};

  data.posts = [];
  data.posts.push({ id: 1, body: 'foo' });
  //...

  return data;
}

docker-json-server's People

Contributors

clue avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.