All Projects → ajoelp → mock-json-server

ajoelp / mock-json-server

Licence: MIT license
A mock web server using a JSON file with live-reload support.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
shell
77523 projects
HCL
1544 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to mock-json-server

Httpmole
A HTTP mole service
Stars: ✭ 127 (+309.68%)
Mutual labels:  mock-server, http-server
gotor
This program provides efficient web scraping services for Tor and non-Tor sites. The program has both a CLI and REST API.
Stars: ✭ 97 (+212.9%)
Mutual labels:  http-server
http-node-api
O objetivo dessa aplicação era criar uma API sem nenhuma dependência externa, apenas utilizando as bibliotecas nativas do NodeJS. Tudo foi feito utilizando 100% Javascript.
Stars: ✭ 44 (+41.94%)
Mutual labels:  http-server
ComplexHTTPServer
ComplexHTTPServer - A Multithreaded Python SimpleHTTPServer
Stars: ✭ 37 (+19.35%)
Mutual labels:  http-server
vcr.js
Mock server with Proxy and Record support inspired by ruby VCR.
Stars: ✭ 41 (+32.26%)
Mutual labels:  mock-server
http-server-online
Start a local HTTP server without any tools, just open a web page.
Stars: ✭ 602 (+1841.94%)
Mutual labels:  http-server
LightWebServer
Java web server using NIO, compatible with http1.1 and support simple MVC function.
Stars: ✭ 38 (+22.58%)
Mutual labels:  http-server
go-docker
Sample code and dockerfiles accompanying the blog post The Ultimate Guide to Writing Dockerfiles for Go Web-apps
Stars: ✭ 89 (+187.1%)
Mutual labels:  live-reload
simple-http
Simple, portable HTTP server for .NET based on HttpListener.
Stars: ✭ 74 (+138.71%)
Mutual labels:  http-server
Pyro-FileStreamBot
Stream Telegram files to web
Stars: ✭ 38 (+22.58%)
Mutual labels:  http-server
tracetrout
A magical reverse traceroute HTTP(S) server
Stars: ✭ 48 (+54.84%)
Mutual labels:  http-server
finch-server
Some base classes and configuration used for making a server using finch
Stars: ✭ 23 (-25.81%)
Mutual labels:  http-server
manta-style
🚀 The futuristic API Mock Server for Frontend
Stars: ✭ 41 (+32.26%)
Mutual labels:  mock-server
gowebview
tool to build android apps with WebView from your golang http server; moved to gitlab.com/microo8/gowebview
Stars: ✭ 35 (+12.9%)
Mutual labels:  http-server
EasyDSS
high performance,industrial rtmp streaming server,a lot of optimization on http,rtmp,hls,http-flv,streaming relay(rtmp pull relay/rtmp push relay),KeyFrame cache,GOP cache,RESTful,and recording, playback, record-download,web management. EasyDSS高性能RTMP流媒体服务器,支持RTMP推流,同步输出HTTP、RTMP、HLS、HTTP-FLV,支持推流分发/拉流分发,支持秒开、GOP缓冲、录像、检索、回放、录像下载、网页管理等多种功能,是目前市面上…
Stars: ✭ 34 (+9.68%)
Mutual labels:  http-server
stirfry
StirFry is a self contained and lightweight web framework for nodejs
Stars: ✭ 24 (-22.58%)
Mutual labels:  http-server
Polyel-Framework
⚡️ Voltis Core: A PHP framework based on Swoole from the ground up
Stars: ✭ 22 (-29.03%)
Mutual labels:  http-server
v4l2web
V4L2 web interface
Stars: ✭ 20 (-35.48%)
Mutual labels:  http-server
hello
Multi-threaded cross-platform HTTP/1.1 web server example in Zig.
Stars: ✭ 29 (-6.45%)
Mutual labels:  http-server
phpkoa
PHP异步编程: 基于 PHP 实(chao)现(xi) NODEJS web框架 KOA。
Stars: ✭ 52 (+67.74%)
Mutual labels:  http-server

Mock Json Server

code style: prettier Build Status

Create a mock server using a json file.

Installation

To install, you need to have NodeJS and NPM installed on your system. Go to https://nodejs.org/en/, download and install one of the provided versions. Both NodeJS and NPM are included.

Install the mock-json-server package by running npm install -g mock-json-server in your terminal.

Using npm v5.6.0 or later? You can skip global installation and directly run npx mock-json-server data.json in a folder containing the below explained data.json.

Thats it!

Example

To run the server run: mock-json-server data.json This starts a server on http://localhost:8000/ you can change the port by running mock-json-server data.json --port=3000

data.json contains:

{
    "/home": {
        "get": {
            "data": [
                {"id":1,"name": "Steve"}
            ]
        },
        "post": {
            "data": [
                {"id":1,"name": "Steve French"}
            ]
        }
    }
}

A Get Request to http://localhost:8000/home will return.

    {
        "data": [
            {"id":1,"name": "Steve"}
        ]
    }

A Post Request to http://localhost:8000/home will return.

    {
        "data": [
            {"id":1,"name": "Steve French"}
        ]
    }

Docker

Mock json server is also a docker image. Run it with the command

docker run --name mock-json-server -v $(pwd)/test/data.json:/usr/src/app/data.json -p 8000:8000 ajoelpod/mock-json-server

Changing the port

Run the same command as above but with the PORT environment variable. Also change the -p to be equal to your new port.

docker run --name mock-json-server --env PORT=3000 -v $(pwd)/test/data.json:/usr/src/app/data.json -p 3000:3000 ajoelpod/mock-json-server

or

Just change the forwared ports

docker run --name mock-json-server -v $(pwd)/test/data.json:/usr/src/app/data.json -p 3000:8000 ajoelpod/mock-json-server

Docker Compose

Example.

version: '3'
services:
  mock-json:
    image: 'ajoelpod/mock-json-server'
    volumes:
      - ./test/data.json:/usr/src/app/data.json
    ports:
      - 8000:8000

Running Programmatically

const server = require('mock-json-server');
const app = server({
  "/home": {
    "get": {
      "data": [{ "id": 1, "name": "Steve" }]
    },
    "post": {
      "data": [{ "id": 1, "name": "Steve French" }]
    }
  },
  "/test/:id": {
    "get": {
      "data": [{ "id": 1, "name": "Steve" }]
    },
    "post": {
      "data": [{ "id": 1, "name": "Steve French" }]
    }
  }
}, 8000); // Start the server with a JSON object;


// Start the server;
app.start();

// Reload the server with new data;
app.reload({ test : true });

// Stop the server
app.stop();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].