What is a JSON server?
JSON Server is a simple, lightweight, and mock server that allows you to quickly create a RESTful API with JSON data. It is often used for prototyping, front-end development, or testing purposes.
With JSON Server, you can define a JSON file as a database and expose RESTful endpoints to perform CRUD (Create, Read, Update, Delete) operations on that data. It provides a fully functional HTTP server that responds to various HTTP methods like GET, POST, PUT, and DELETE.
HOW TO MAKE A JSON SERVER IN REACT APP?
STEP1: Create a server folder in the react-js app
STEP2: In the server folder, Initialize the package.json file and install the JSON-server using the following commands.
npm init -y
npm i json-server
STEP 3: Create a db.json file in the server folder and write the data in the db.json file.
STEP 4: Configure the package.json file. Add the following command in the scripts.
"scripts": {
"start": "json-server --watch db.json -p 9000"
},
STEP 5: In The terminal, go to the server folder, and run the npm start command.
Comments
Post a Comment