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

314 questions
25
votes
5 answers

json-server cannot access via local IP

I'm using npm json-server from here. It used to work great for my needs: run a server on my PC and do GET requests to local IP (192.168.1.XX). I reinstalled it and now I can do requests only to localhost or 127.0.0.1. Can't do requests to local IP…
Choletski
  • 5,702
  • 5
  • 36
  • 49
12
votes
6 answers

json-server is not recognized as an internal or external command

I am setting up a json-server and I install it and assign it to be my npm start command like so "scripts": { "start": "json-server -p 3001 -w db.json" but every time I type npm start on the terminal I got this error > api-server@1.0.0 start…
Abdelaziz Mohamed
  • 123
  • 1
  • 1
  • 7
10
votes
3 answers

Can you deploy a fake backend run by json-server NPM module using Heroku?

I often use the npm module json-server to generate a fake JSON api given a db.json file. Is there any way to deploy that to Heroku? Essentially, I just run json-server --watch db.json And it runs a server that also servers static html if there are…
nbkhope
  • 6,516
  • 2
  • 32
  • 53
8
votes
2 answers

How to access 'rel' from Links in header? Hypermedia link relations

I am using json server and axios result from header link: "; rel="first", ; rel="next", ; rel="last"" How can I use/access these data…
Þaw
  • 1,969
  • 2
  • 19
  • 37
6
votes
1 answer

OR operator in json-server

I can fetch data from json-server (fake server) by calling: http://localhost:3000/posts?title_like=head&comments_like=today This will return records where title likes "head" AND comments like "today". What if I want not AND but OR operator?
O. Shekriladze
  • 833
  • 4
  • 24
6
votes
0 answers

Running json-server in docker

I've been running json-server in a docker container for a while successfully with the following config: Docker File: FROM node:alpine EXPOSE 3000 COPY deploy/conf/mockBackend.json /opt/mockBackend.json RUN yarn global add json-server CMD…
Pabi
  • 651
  • 2
  • 10
  • 18
6
votes
5 answers

Create Simple Node.js API from JSON files

I have a folder of JSON files that I'd like to use to create a simple API from. Here's a simplified version of my folder structure: /clients.json /clients/1/client.json /clients/2/client.json ... my /clients.json file looks like this: [ { …
DanV
  • 2,874
  • 3
  • 25
  • 39
5
votes
1 answer

json-server - Using nested request

I just start using json-server and struggling with one thing. I want to have URL which are nested so e.g. to get user orgs, request would looks like: /rest/user/orgs and will return array of user orgs { "rest": { "user": { …
Andurit
  • 4,879
  • 8
  • 60
  • 100
5
votes
4 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,583
  • 4
  • 38
  • 57
4
votes
1 answer

Custom routes in json-server for nested endpoint

To test client's ApiService class I need to replace my real backend URL by a mock and for these purposes I chose json-server. I set up a proxy config to forward all requests that starts with http://localhost:4200/v1/api to http://localhost:3000: { …
Шах
  • 5,849
  • 7
  • 38
  • 79
4
votes
6 answers

Is it possible to do expressions/calculations in json?

I am using the wonderful json-server as the backend of my application and it's really useful for hitting custom endpoints to retrieve some data. but what would be super useful if it allowed me to do calculations/expression so that i can mimic that…
Red Baron
  • 4,499
  • 4
  • 18
  • 53
4
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
  • 109
  • 2
  • 7
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
  • 2,637
  • 7
  • 37
  • 80
4
votes
2 answers

Type of “id” (number) in user.json is not supported. Use objects or arrays of objects error when using json-server, why?

I am working on an Angular 4 App. I am trying to get data from a JSON file for building a user dashboard. I created a json file and tried loading it using JSON server using this: $ json-server --watch user.json and I am getting the following…
4
votes
2 answers

json-server can we use other key instead of id for post and put request

I have fake api for testing in frontend side. i have seen that id is required to put or post your data in json-server package, my question is can i use different key instead of id for ex. { id: 1, ---> i want to change this with my custom id …
Tameshwar
  • 761
  • 10
  • 16
1
2 3
20 21