Coder Social home page Coder Social logo

chanioxaris / json-server Goto Github PK

View Code? Open in Web Editor NEW
36.0 3.0 1.0 174 KB

Create a dummy REST API from a json file with zero coding in seconds

License: MIT License

Go 100.00%
json json-api rest-api api mock-server json-server jsonapi rest development-tools development

json-server's Introduction

JSON Server

License: MIT GoDoc Release

codecov goreportcard

Create a dummy REST API from a json file with zero coding in seconds. Helps you to continue your development process when an API you depend on, doesn't exist or isn't complete yet.

Inspired from json-server javascript package.

Executables

Cross-platform (Windows, Linux, macOS) binaries are available for download. Select the executable that match your Operating System and run json-server without any dependencies, with minimum effort.

Getting started

Get the package

go get github.com/chanioxaris/json-server

Create a db.json file with your desired data

{
  "posts": [
    { 
       "id": "1", 
       "title": "json-server", 
       "author": "chanioxaris" 
    }
  ],
   "books": [
     {
       "id": "1",
       "title": "Clean Code",
       "published": 2008,
       "author": "Robert Martin"
     },
     {
       "id": "2",
       "title": "Crime and punishment",
       "published": 1866,
       "author": "Fyodor Dostoevsky"
     }
   ]
}

Start JSON Server

go run main.go start

If you navigate to http://localhost:3000/posts/1, you will get

{ 
  "id": "1", 
  "title": "json-server", 
  "author": "chanioxaris" 
}

Routes

Based on the previous json file and for each resource, the below routes will be generated

GET     /<resource>
GET     /<resource>/:id
POST    /<resource>
PUT     /<resource>/:id
PATCH   /<resource>/:id
DELETE  /<resource>/:id

When doing requests, it's good to know that:

  • For POST requests any id value in the body will be honored, but only if not already taken.
  • For POST requests without id value in the body, a new one will be generated.
  • For PUT requests any id value in the body will be ignored, as id values are not mutable.
  • For PATCH requests any id value in the body will be ignored, as id values are not mutable.

Parameters

  • You can specify an alternative port with the flag -p or --port. Default value is 3000.

go run main.go start -p 4000

  • You can specify an alternative file with the flag -f or --file. Default value is db.json.

go run main.go start -f example.json

  • You can toggle http request logs with the flag -l or --logs. Default value is false.

go run main.go start -l

Known issues

  • For users running macOS Catalina and newer versions, apple will prevent binary from run as it hasn't been notarized and signed. To overcome this issue, you can add a security exception for json-server.

Contributing

Contributions to this project are welcomed. For more information see the contribution guidelines.

License

json-server is MIT licensed.

json-server's People

Contributors

chanioxaris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ocomsoft

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.