You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+77-2Lines changed: 77 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# Actix-web REST API
1
+
# Actix-web REST API with JWT
2
2
3
-
A simple CRUD backend app using Actix-weband Diesel
3
+
A simple CRUD backend app using Actix-web, Diesel and JWT
4
4
5
5
# Require
6
6
@@ -9,6 +9,7 @@ A simple CRUD backend app using Actix-web and Diesel
9
9
10
10
# How to run
11
11
12
+
- Rename `secret.key.sample` to `secret.key` or create your own key by running `head -c16 /dev/urandom > secret.key` in command line (Linux/UNIX only) and copy to `/src` folder
12
13
- Create a database in postgres cli or [pgAdmin](https://www.pgadmin.org/) tool
13
14
- Rename `.env.sample` to `.env` and update the database connection string in `DATABASE_URL` key.
14
15
- Build with release profile: `cargo build --release`
@@ -29,7 +30,60 @@ A simple CRUD backend app using Actix-web and Diesel
29
30
pong!
30
31
```
31
32
33
+
### `POST /api/auth/signup`: Signup
34
+
- Request body:
35
+
```
36
+
{
37
+
"username": string,
38
+
"email": string,
39
+
"password": string // a raw password
40
+
}
41
+
```
42
+
- Response
43
+
- 200 OK
44
+
```
45
+
{
46
+
"message": "signup successfully",
47
+
"data": ""
48
+
}
49
+
```
50
+
- 400 Bad Request
51
+
```
52
+
{
53
+
"message": "User '{username}' is already registered",
54
+
"data": ""
55
+
}
56
+
```
57
+
58
+
### `POST /api/auth/login`: Login
59
+
- Request body:
60
+
```
61
+
{
62
+
"username_or_email": string,
63
+
"password": string // a raw password
64
+
}
65
+
```
66
+
- Response
67
+
- 200 OK
68
+
```
69
+
{
70
+
"message": "login successfully",
71
+
"data": {
72
+
"token": string // bearer token
73
+
}
74
+
}
75
+
```
76
+
- 400 Bad Request
77
+
```
78
+
{
79
+
"message": "wrong username or password, please try again",
80
+
"data": ""
81
+
}
82
+
```
83
+
32
84
### `GET /api/address-book`: Get all people information
85
+
- Header:
86
+
- Authorization: bearer \<token\>
33
87
- Response
34
88
- 200 OK
35
89
```
@@ -52,6 +106,8 @@ A simple CRUD backend app using Actix-web and Diesel
52
106
### `GET /api/address-book/{id}`: Get person information by id
53
107
- Param path:
54
108
- id: int32
109
+
- Header:
110
+
- Authorization: bearer \<token\>
55
111
- Response
56
112
- 200 OK
57
113
```
@@ -79,6 +135,8 @@ A simple CRUD backend app using Actix-web and Diesel
79
135
### `GET /api/address-book/{query}`: Search for person information by keyword
80
136
- Param path:
81
137
- query: string
138
+
- Header:
139
+
- Authorization: bearer \<token\>
82
140
- Response
83
141
- 200 OK
84
142
```
@@ -99,6 +157,8 @@ A simple CRUD backend app using Actix-web and Diesel
99
157
```
100
158
101
159
### `POST /api/address-book`: Add person information
160
+
- Header:
161
+
- Authorization: bearer \<token\>
102
162
- Request body:
103
163
```
104
164
{
@@ -129,6 +189,8 @@ A simple CRUD backend app using Actix-web and Diesel
129
189
### `PUT /api/address-book/{id}`: Update person information by id
130
190
- Param path:
131
191
- id: int32
192
+
- Header:
193
+
- Authorization: bearer \<token\>
132
194
- Request body:
133
195
```
134
196
{
@@ -159,6 +221,8 @@ A simple CRUD backend app using Actix-web and Diesel
159
221
### `DELETE /api/address-book/{id}`: Delete person information by id
160
222
- Param path:
161
223
- id: int32
224
+
- Header:
225
+
- Authorization: bearer \<token\>
162
226
- Response
163
227
- 200 OK
164
228
```
@@ -174,3 +238,14 @@ A simple CRUD backend app using Actix-web and Diesel
0 commit comments