Skip to content

tkc/go-json-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go

  ___          _                 ___                      
 / __|___   _ | |__ _ ___ _ _   / __| ___ _ ___ _____ _ _ 
| (_ / _ \ | || / _` / _ \ ' \  \__ \/ -_) '_\ V / -_) '_|
 \___\___/  \__/\__,_\___/_||_| |___/\___|_|  \_/\___|_|  
                                                          

simple and quick golang JSON mock server.
simulate an http server and return the specified json according to a custom route.

  • static json api server
  • static file server
  • cache response and reload
  • change api.json path
  • url param
  • server deamon
  • jwt or session auth
  • error response
  • access log
  • E2E test sample source in Github Actions

Install

$ go get -u github.com/tkc/go-json-server

Prepare api.json

- api.json // required 
- response.json

See example
https://github.com/tkc/go-json-server/tree/master/example

Serve Mock Server

$ go-json-server

Sample Json Setting

api.json

{
  "port": 3000,
  "endpoints": [
     {
      "method": "GET",
      "status": 200,
      "path": "/",
      "jsonPath": "./health-check.json"
    },
    {
      "method": "GET",
      "status": 200,
      "path": "/users",
      "jsonPath": "./users.json"
    },
    {
      "method": "GET",
      "status": 200,
      "path": "/user/1",
      "jsonPath": "./user.json"
    },
    {
      "path": "/file",
      "folder": "./static"
    }
  ]
}

health-check.json

{
    "status": "ok",
    "message": "go-json-server"
}

users.json

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

user.json

{
  "id": 1,
  "name": "name",
  "address": "address"
}

License

MIT ✨