Questions tagged [json-server]

json-server allows you to rapidly create a REST API server that delivers JSON data.

json-server is a tool written in that allows you to rapidly create a server that when started up, delivers json data via a API.

You can use json-server for rapid prototyping and mocking out other REST API services.

Supply a JSON file to describes the JSON data and the API that will deliver it and json-server will start up a server that provides that data via a REST API

Source Code and further documentation https://github.com/typicode/json-server

Installation npm install json-server

Egghead Video (free) Nodejs: Creating demo apis with json-server

477 questions
5
votes
3 answers

POST collection of objects in json-server

I am using json-server to fake the Api for the FrontEnd team. We would like to have a feature to create the multiple objects (Eg. products) in one call. In WebApi2 or actual RestApis, it can be done like the following: POST api/products //For Single…
TTCG
  • 8,805
  • 31
  • 93
  • 141
5
votes
3 answers

Path with '/' in json-server db.json

i use server-json to have a fake API, i have the path "playbook/active" in data.json "playbook/active": [{ "description": "This playbook will install haproxy", "name": "Testing playbook 3", "tag": [ "loadbalancer", "charge" …
Khaled Ayed
  • 1,121
  • 3
  • 12
  • 29
5
votes
1 answer

How add headers on json-server?

I have frontend and backend on different servers. I need make crossdomain request. On localhost:4200 i use angular2. On localhost:3000 i use json-server. Еhe server should give the header: Access-Control-Allow-Origin: * But I do not know how to…
provoter33
  • 119
  • 2
  • 7
5
votes
2 answers

How to host json-server in azure

I am new in the software field, please have patience with my question and mistakes of technical terms: Premises:- I have developed an front-end application using Angular4. The baseURL define in angular application is 'http://localhost:3000/'. My…
Raj
  • 77
  • 2
  • 5
5
votes
5 answers

Resetting json-server to the contents of db.json

NOTHING I do will get json-server to acknowledge changes to the db.json file. After reading https://github.com/typicode/json-server/issues/177. I have tried clearing the cache and closed all browser connections etc. (which is a pain enough in a…
kpollock
  • 3,899
  • 9
  • 42
  • 61
4
votes
2 answers

Axios mock adapter giving error 'Error: Request failed with status code 404'

I have a component in which I am making an API call on mount import * as React from 'react'; import axios from 'axios'; import './index.scss'; // import {axiosInstance} from '../../mocks/index'; // axios(client) // axiosInstance(axios); const…
Aayushi
  • 1,736
  • 1
  • 26
  • 48
4
votes
1 answer

Best practices to deploy a React app and an API on Heroku

I'm currently working on a project using React (via create-react-app) and JSONServer for the API. I have a single Git repository structured as follow : |-- client |-- api To work in a dev environment, I start both of the folders with npm start in…
user990463
  • 439
  • 1
  • 7
  • 27
4
votes
1 answer

Node JSON-Server returning MOCK post response

I'm trying to use https://www.npmjs.com/package/json-server as a mock backend, I'm able to match URLs for get, but how can i return some mock-response for POST calls. Like for create user URL will be like URL - http://localhost:4000/user …
Anup Singh
  • 1,513
  • 3
  • 16
  • 32
4
votes
2 answers

Custom routes in json-server using Node.js

I found problem when using custom routes for requesting db.json which is deployed in json-server. For example for this given json as below, I'd like to access voters by name, so when I type…
Mohamed Aoutir
  • 613
  • 3
  • 11
  • 22
4
votes
3 answers

json-server getting error after post request

I am working with json-server and I am getting following error. What I am doing wrong? TypeError: Cannot read property 'id' of undefined [0] at Function.createId …
Noah Tony
  • 373
  • 3
  • 7
  • 18
4
votes
1 answer

Concurrently node exits with status 1. This halts Teamcity leading it to believe that the tests failed

I am trying to run two scripts at once with concurrently. The basic command looks something like this: concurrently -k --success first "node ./tools/mock-webapi/mock-webapi.js" "npm run test-single-run" Which in turn calls…
Adrian Moisa
  • 3,923
  • 7
  • 41
  • 66
4
votes
5 answers

How to use method delete with Json-server and Axios?

i'm doing a project and using json-server and axios.js, but i am with problem in the method delete. My axios.js: remove = (id) => { axios.delete('http://127.0.0.1:3000/people/', id) .then(function(response) { this.setState({ …
Jota
  • 819
  • 6
  • 24
  • 41
4
votes
0 answers

gulp task with gulp-run-command doesn't work properly

I'm trying to run json-server in a gulp task and I'm checking if the server runs, with the function portInUse. Like this: var gulputil = require('gulp-util') var run = require('gulp-run-command').default var gulp = require('gulp') const args = [ …
Steve Waters
  • 3,348
  • 9
  • 54
  • 94
3
votes
1 answer

Relation in Json-server

I want to create a database using "json-server" and I also used the "relation" topic, but I can't get the products of the user's shopping cart? Where is the problem? Thank you for helping me. My "db.json" file example is as follows: { "products":…
Ali Rahimi
  • 33
  • 4
3
votes
0 answers

Cypress cannot connect to json-server localhost in Github Action

I have a very basic application which has an html/js frontend, and a json DB hosted by json-server. I have setup a simple e2e test suite in Cypress with 2 tests. This runs completely fine locally, but when I run this on GitHub Actions I get an…
1
2
3
31 32