Skip to content

Commit e48c9fd

Browse files
committed
Initial commit
0 parents commit e48c9fd

File tree

7 files changed

+1991
-0
lines changed

7 files changed

+1991
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# JSONServer + JWT Auth
2+
3+
A Fake REST API using json-server with JWT authentication. You can find the [complete tutorial here](https://www.techiediaries.com/fake-api-jwt-json-server/)
4+
5+
## Install
6+
7+
```bash
8+
$ npm install
9+
$ npm run api-auth
10+
```
11+
12+
## How to login?
13+
14+
You can login by sending a POST request to
15+
16+
```
17+
POST http://localhost:3000/auth/login
18+
```
19+
with the following data
20+
21+
```
22+
{
23+
"email": "nilson@email.com",
24+
"password":"nilson"
25+
}
26+
```
27+
28+
You should receive an access token with the following format
29+
30+
```
31+
{
32+
"access_token": "<ACCESS_TOKEN>"
33+
}
34+
```
35+
36+
37+
You should send this authorization with any request to the protected endpoints
38+
39+
```
40+
Authorization: Bearer <ACCESS_TOKEN>
41+
```
42+
43+

database.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"products": [
3+
{
4+
"id": 1,
5+
"name": "Product001",
6+
"cost": 10.0,
7+
"quantity": 1000,
8+
"locationId" : 1,
9+
"familyId" : 1
10+
},
11+
{
12+
"id": 2,
13+
"name": "Product002",
14+
"cost": 20.0,
15+
"quantity": 2000,
16+
"locationId" : 1,
17+
"familyId" : 2
18+
},
19+
{
20+
"id": 3,
21+
"name": "Product003",
22+
"cost": 30.0,
23+
"quantity": 3000,
24+
"locationId" : 3,
25+
"familyId" : 2
26+
},
27+
{
28+
"id": 4,
29+
"name": "Product004",
30+
"cost": 40.0,
31+
"quantity": 4000,
32+
"locationId" : 2,
33+
"familyId" : 3
34+
}
35+
],
36+
"locations":[
37+
{
38+
"id": 1,
39+
"name": "Location001"
40+
},
41+
{
42+
"id": 2,
43+
"name": "Location002"
44+
},
45+
{
46+
"id": 3,
47+
"name": "Location003"
48+
}
49+
],
50+
"families":[
51+
{
52+
"id": 1,
53+
"name": "FM001"
54+
},
55+
{
56+
"id": 2,
57+
"name": "FM002"
58+
},
59+
{
60+
"id": 3,
61+
"name": "FM003"
62+
}
63+
],
64+
"transactions":[
65+
{
66+
"id": 1,
67+
"cost":11,
68+
"quantity":10,
69+
"productId":1
70+
},
71+
{
72+
"id": 2,
73+
"cost":12,
74+
"quantity":100,
75+
"productId":2
76+
},
77+
{
78+
"id": 3,
79+
"cost":15,
80+
"quantity":101,
81+
"productId":3
82+
}
83+
]
84+
}

0 commit comments

Comments
 (0)