Questions tagged [json-server]
json-server allows you to rapidly create a REST API server that delivers JSON data.
json-server
502
questions
40
votes
8
answers
50k
views
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 ...
39
votes
7
answers
143k
views
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 ...
12
votes
1
answer
12k
views
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
...
12
votes
3
answers
9k
views
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 ...
10
votes
2
answers
3k
views
How to access 'rel' from Links in header? Hypermedia link relations
I am using json server and axios
result from header
link: "<http://localhost:3001/posts?_page=1>; rel="first", <http://localhost:3001/posts?_page=2>; rel="next", <http://localhost:...
9
votes
1
answer
9k
views
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 ...
8
votes
6
answers
20k
views
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 ...
7
votes
6
answers
68k
views
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 ...
7
votes
1
answer
18k
views
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 ...
7
votes
4
answers
16k
views
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, ...
7
votes
1
answer
2k
views
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 "...
7
votes
0
answers
8k
views
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/...
6
votes
2
answers
7k
views
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 --...
6
votes
3
answers
9k
views
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",
...
6
votes
5
answers
2k
views
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
......
5
votes
3
answers
10k
views
json-server - strange autoincrement id
I've got a problem with id-autoincrementation on my json-server. I set up a simple default json-server with single db.json file to watch.
Here is my db.json file (simple generated data):
{
"users":...
5
votes
2
answers
6k
views
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 ...
5
votes
3
answers
13k
views
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 ...
5
votes
5
answers
15k
views
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 ...
5
votes
2
answers
13k
views
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';
// ...
5
votes
1
answer
7k
views
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-...
5
votes
2
answers
21k
views
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 this
url:
...
5
votes
1
answer
5k
views
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://...
4
votes
3
answers
11k
views
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
(/Users/Picchu/Documents/...
4
votes
1
answer
12k
views
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 ...
4
votes
3
answers
6k
views
Unexpected errors and warnings when running json-server --watch
I'm trying to use json-server as follows:
$ json-server --watch db.json
However, I'm getting errors or warnings when I run that command, depending on the version I have installed:
1.0.0-alpha.1-1.0....
4
votes
2
answers
10k
views
no cors config not working with json-server
I'm using json-server to create a mock API of my actual API for offline testing purpose.
I can see the mock API response under their Url endpoint:
localhost:5001/api/searchresults/*
but on my app I ...
4
votes
1
answer
4k
views
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,...
4
votes
5
answers
24k
views
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)
....
4
votes
1
answer
5k
views
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-...
4
votes
0
answers
331
views
json-server : how to do complex queries
I have a set of users each with a team id.
I have a set of records which are 'owned' by a user.
e.g.
users: [
{ id: 1, teamId: 1234 },
...
],
records: [
{ id: 1, usersId: 1 },
....
]
Can I issue an ...
4
votes
0
answers
99
views
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')....
3
votes
3
answers
2k
views
json-server running but can't access its api due to 403
Learning reactjs, trying to simulate a server with json-server
this is my script to run the server:
"scripts": {
"server": "json-server --watch db.json --port 5000"
},...
3
votes
1
answer
4k
views
Can't install json-server
I am trying to install JSON-Server, but it's not working!
I have used the following command: npm install -g json-server
Here is the error message:
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! ...
3
votes
6
answers
9k
views
How to use json-server | Getting 404 for local db.json
I'm pretty sure doing everything correctly. I'm using these version:
"axios": "^0.24.0",
"json-server": "^0.17.0",
I've followed the official doc. I've db.json ...
3
votes
3
answers
4k
views
JSON-server connection breaks
I'm using GET and POST requests to apply RESTful conventions multiple times in my application. But this results in breaking my JSON-server connection. Does anyone know what is the reason behind this? ...
3
votes
1
answer
2k
views
Can't redirect traffic to localhost with nginx and docker
I'm new to Docker and nginx so this may be a simple question but I've been searching through question/answers for a while and haven't found the correct solution.
I'm trying to run an nginx server ...
3
votes
1
answer
5k
views
Is there a way to generate swagger.json from json-server file
For prototyping we are using json-server library that creates fake REST api based on our db.json file. Now we would like to use swagger.
So my question is, is there a way to generate swagger.json ...
3
votes
1
answer
5k
views
React Multiple Fetch from state
so I am trying to fetch my SWAPI json-server twice using the homeworld id to get the homeworld name but I just get "TypeError: Cannot read property 'name' of undefined". Im fairly new to React so if ...
3
votes
1
answer
2k
views
Custom POST with json-server, request.body === undefined
I am using https://github.com/typicode/json-server to mock data for a project.
I have set up the server according to the documentation, but when creating a custom POST request, using curl:
curl 'http:/...
3
votes
1
answer
510
views
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 ...
3
votes
2
answers
2k
views
jsonserver not redirecting using rewriter
I have an employees endpoint with some data in my db.json. I'm using node v6.14.9.
My server.js looks like this:
// server.js
const jsonServer = require('json-server')
const server = jsonServer.create(...
3
votes
1
answer
6k
views
How to access nested resources in JSON server
I am trying to use json-server for my application.
My json file goes like this:
{
"Categories": [
{
"item": [
{
"id": 1,
"product_id": 1,
"...
3
votes
1
answer
2k
views
API call not reaching Vite proxy target (localhost:5000)
So I'm trying to learn Vue and I've set up a project and a json-server backend, both running with Docker. Almost everything is working as intended.
I've written a function to fetch the tasks in the ...
3
votes
1
answer
2k
views
json-server with express/ db.json is not reflecting changes
We are having a simple json-server setup, loading it as a module.
However, when making a POST/PUT request, the data is not being injected into the db.json.
const jsonServer = require("json-server");
...
3
votes
1
answer
779
views
Syntax for json-server middlewares
I am trying to use middleware in json-server, just to append specific properties to body response at specific routes. I have this working code:
server.use(jsonServer.bodyParser);
server.use((req, res,...
3
votes
0
answers
707
views
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 ...
3
votes
0
answers
468
views
How to return value from json-server on post request?
The issue
GET /api/get-request works correctly, and `{ x: 'x' } is returned to the frontend
POST /api/post-request works too but returns empty body
How I run json-server:
json-server src/configs/...
3
votes
0
answers
2k
views
Vue and Json-server hosted on Vercel
I'm currently writing frontend app in Vue.js. Until I have a real web API, I've decided to use json-server. Now I'm trying to configure Vercel to start my json-server alongside Vue during deployment. ...
3
votes
0
answers
301
views
React Admin - ReferenceInput with multiple fields output
I'm using React with React Admin to populate my database in which I have 2 collections: products and stores
I need to link a store to the product, so normally I should do:
<ReferenceInput label=&...