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
37
votes
8 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
  • 7,074
  • 6
  • 43
  • 64
36
votes
7 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
  • 363
  • 1
  • 3
  • 8
12
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
  • 5,612
  • 14
  • 69
  • 121
11
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
  • 7,360
  • 4
  • 40
  • 58
10
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
  • 2,047
  • 4
  • 22
  • 39
9
votes
1 answer

How to get json-server, when used as module, to delay responses?

json-server allows one to configure responses to be delayed via the command line: json-server --port 4000 --delay 1000 db.json How does one try to do this when using json-server as a module? The following doesn't work: const jsonServer =…
rityzmon
  • 1,945
  • 16
  • 26
7
votes
1 answer

How can I filter a get request to a json-server with specific search queries?

I have installed a Json-Server. Get-Requests to this server are delivering the expected data but now I want to add some search queries to my request. But the result is still the same. I don't know whats my mistake here. Here is my…
Stefan Winkler
  • 71
  • 1
  • 1
  • 2
7
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
  • 1,346
  • 1
  • 19
  • 36
7
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
  • 7,181
  • 10
  • 39
  • 86
7
votes
4 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
  • 789
  • 1
  • 10
  • 17
6
votes
4 answers

Command json-server --watch db.json is not working - it returns"'json-server' command not found"

I set a JSON file to use as a little practice database, but I can't run the server. I've already tried to install (and reinstall) json-server global and locally npm install -g json-server and npm install json-server and then run json-server --watch…
Angelo Fonseca
  • 61
  • 1
  • 1
  • 3
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
  • 891
  • 3
  • 12
  • 18
6
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…
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
  • 3,193
  • 4
  • 29
  • 43
5
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: { …
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
1
2 3
31 32