Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abhisek753/json_server
Json server deployment for an Fronted Application
https://github.com/abhisek753/json_server
db json-api json-api-response
Last synced: 6 days ago
JSON representation
Json server deployment for an Fronted Application
- Host: GitHub
- URL: https://github.com/abhisek753/json_server
- Owner: Abhisek753
- Created: 2022-12-22T17:42:46.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T07:53:40.000Z (almost 2 years ago)
- Last Synced: 2024-11-06T21:25:07.582Z (about 2 months ago)
- Topics: db, json-api, json-api-response
- Language: JavaScript
- Homepage: https://effulgent-salamander-1adc45.netlify.app/
- Size: 49.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
bankapp-mock-api
Created db.json data for fronted
#### Prerequisite
* Create a folder
```
mkdir bankapp-mock-api
cd bankapp-mock-api
```#### Step 1: Create a node js project
```
npm init -y
```#### Step 2: Install json server dependency
```
npm i json-server
```#### Step 3: Create server.js
```js
const jsonServer = require('json-server')const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()
server.use(middlewares)
server.use('/api', router)
server.listen(process.env.PORT || 5000, () => {
console.log('JSON Server is running')
})```
#### Step 4: Create db.json
```js
{
"users": [
{ "id": 1, "name":"Naresh Kumar H", "email":"[email protected]",
"password":"pass123", "role": "USER"
},
{ "id": 2, "name":"Tushant", "email":"[email protected]",
"password":"pass123", "role": "ADMIN"
}
],
"accounts":[],
"transactions":[]
}
```#### Step 5: Run the Node JS Project
```
node server.js
```#### Step 6: Test - List Users API
```
http://localhost:5000/api/users
```Output:
```js
[
{
id: 1,
name: "Naresh Kumar H",
email: "[email protected]",
password: "pass123",
role: "USER"
},
{
id: 2,
name: "Tushant",
email: "[email protected]",
password: "pass123",
role: "ADMIN"
}
]
```#### Step 7: Test - View User Details API
```
http://localhost:5000/api/users/1
```Output:
```js
{
id: 1,
name: "Naresh Kumar H",
email: "[email protected]",
password: "pass123",
role: "USER"
}
```