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
0
votes
1 answer

json-server middleware not working as expected

using node.js/Express/json-server I am trying to check ( and modify) the request url sent to my API json-server. I wrote as stated the following middleware in my app server.js // API JSON-SERVER const jsonServer = require('json-server') const…
user762579
0
votes
1 answer

json-server : how to write correct endpoints

If I have a json file like this : { "users": { "count": 157, "rows": [...data] }, "gifts": { ...} } How can I write endpoints to get the users.count and the users.rows ? thanks for feedback
user762579
0
votes
1 answer

mapping return data from a fetch call to state causing error

I am attempting to use a direct fetch to JSON.server to retrieve a basic package to load some simple components. When I run this script in Firefox. I get a "Network Error when attempting to fetch the resource" but cannot find any 400 errors in the…
jpearsonNode
  • 61
  • 1
  • 3
  • 13
0
votes
1 answer

Error about CORS when anuglar accesses my-json-server on stackblitz

On stackblitz, I built an Angular project to access my-json-server mock server. It's here. Once clicking Send Request button, I got the following error on console: Failed to load https://my-json-server.typicode.com/typicode/demo/posts/1: No…
niaomingjian
  • 3,472
  • 8
  • 43
  • 78
0
votes
1 answer

Multiple ID's in REST endpoints

coming from a Wordpress background my knowledge on using REST API's is quite limited. I've started using JSON server (dummy local rest API) to learn the ins and outs. Looking at the documentation, there doesn't seem to be any way to delete, update…
Samuel
  • 2,485
  • 5
  • 30
  • 40
0
votes
1 answer

JSON-Server: Mocking a endpoint with parameters

I am trying to mock the service response using JSON-server. Actual URL is: message-service/notifications?id=xyx I am mocking this URL to hit a dummy URL through JSON-server: { "/message-service/notifications?id=:id": "/notifications/:id" } my…
TnJ
  • 43
  • 4
0
votes
1 answer

Error : The database is a JavaScript file but the export is not a function

I'm trying to use json-server to generate some fake data. Here is the Node.js code: // data.js function generateData1() { test = []; return { "test": test } } function generateData2() { test = []; return { …
iJade
  • 23,144
  • 56
  • 154
  • 243
0
votes
1 answer

How to store array of objects in db.json from json-server

I am creating a fake backend using json-server to store some data in json format. The data is complex as follows - { "id": 0, "quizName": "Which Harry Potter Character Are You?", "characters": ["Harry", "Ron",…
Praful Surve
  • 788
  • 1
  • 10
  • 22
0
votes
1 answer

Why is json-server's (nodejs plugin) package.json running when I do git push?

Any time I run git push, a package in node_modules runs which breaks my push and I get the error you see in my git error response. My setup is pretty basic. (Gulp,few other dependencies, and json-server) none of the other projects are trying to…
Jessy
  • 1,150
  • 16
  • 27
0
votes
2 answers

Configure redirect of all $http & $resource calls to other endpoint

I would like to run a mock server e.g. JSON Server, and switch between my real Java REST API backend and this JSON Server during development (for instance when real backend services are down). Is there a way to easily configure angular to use a…
dragonfly
  • 17,407
  • 30
  • 110
  • 219
0
votes
1 answer

Create and Update JSON calls not working

I am learning Angular 2 and have an interesting issue. I am using json-server to mock my service calls and retrieve works well. However I have issues with Create and Update. I am using a basic model called notification which looks like so:- export…
Campey
  • 1,108
  • 9
  • 15
0
votes
1 answer

CastError: Cast to ObjectId failed for value "NaN" at path "_id"

[ Issue now resolved... the answer was ridiculously simple... $scope.article = articleFactory.getArticles().get({id:parseInt($stateParams.id,10)}) .$promise.then( should have read: $scope.article =…
Stef
  • 359
  • 1
  • 4
  • 21
0
votes
2 answers

node.js request post retrieve last id from db.json

After posting in db.json a new record (transaction with several data), I would like to get the id of the new record before going on. How-to do it ? I am stuck I have in my db.json a "table" positions with an id automatically generated my request is…
olivier
  • 1
  • 4
0
votes
2 answers

Angular, push JSON object to server

I am using json-server and db.json, in db.json file I have a currently empty array "feedback":[] where user should be able to send feedbacks from the app. but nothing get pushed into server, the get method works (GET from server) but no PUT this is…
Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123
0
votes
1 answer

How to create composite Json object working with Typicode Json Server

I am working in a Web Application using jQuery and I am confused about the JSON format. For the server I am using a restful Json Server. The problem is that don't know what is the problem. The error is that the Json format that i post to the server…
shogitai
  • 1,823
  • 1
  • 23
  • 50