Skip to content

Commit 2469339

Browse files
authored
Merge pull request #6 from SakaDream/actix-jwt
[actix-jwt] Update README
2 parents f92db34 + ec2ac4c commit 2469339

File tree

1 file changed

+77
-2
lines changed

1 file changed

+77
-2
lines changed

README.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Actix-web REST API
1+
# Actix-web REST API with JWT
22

3-
A simple CRUD backend app using Actix-web and Diesel
3+
A simple CRUD backend app using Actix-web, Diesel and JWT
44

55
# Require
66

@@ -9,6 +9,7 @@ A simple CRUD backend app using Actix-web and Diesel
99

1010
# How to run
1111

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
1213
- Create a database in postgres cli or [pgAdmin](https://www.pgadmin.org/) tool
1314
- Rename `.env.sample` to `.env` and update the database connection string in `DATABASE_URL` key.
1415
- Build with release profile: `cargo build --release`
@@ -29,7 +30,60 @@ A simple CRUD backend app using Actix-web and Diesel
2930
pong!
3031
```
3132
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+
3284
### `GET /api/address-book`: Get all people information
85+
- Header:
86+
- Authorization: bearer \<token\>
3387
- Response
3488
- 200 OK
3589
```
@@ -52,6 +106,8 @@ A simple CRUD backend app using Actix-web and Diesel
52106
### `GET /api/address-book/{id}`: Get person information by id
53107
- Param path:
54108
- id: int32
109+
- Header:
110+
- Authorization: bearer \<token\>
55111
- Response
56112
- 200 OK
57113
```
@@ -79,6 +135,8 @@ A simple CRUD backend app using Actix-web and Diesel
79135
### `GET /api/address-book/{query}`: Search for person information by keyword
80136
- Param path:
81137
- query: string
138+
- Header:
139+
- Authorization: bearer \<token\>
82140
- Response
83141
- 200 OK
84142
```
@@ -99,6 +157,8 @@ A simple CRUD backend app using Actix-web and Diesel
99157
```
100158
101159
### `POST /api/address-book`: Add person information
160+
- Header:
161+
- Authorization: bearer \<token\>
102162
- Request body:
103163
```
104164
{
@@ -129,6 +189,8 @@ A simple CRUD backend app using Actix-web and Diesel
129189
### `PUT /api/address-book/{id}`: Update person information by id
130190
- Param path:
131191
- id: int32
192+
- Header:
193+
- Authorization: bearer \<token\>
132194
- Request body:
133195
```
134196
{
@@ -159,6 +221,8 @@ A simple CRUD backend app using Actix-web and Diesel
159221
### `DELETE /api/address-book/{id}`: Delete person information by id
160222
- Param path:
161223
- id: int32
224+
- Header:
225+
- Authorization: bearer \<token\>
162226
- Response
163227
- 200 OK
164228
```
@@ -174,3 +238,14 @@ A simple CRUD backend app using Actix-web and Diesel
174238
"data": ""
175239
}
176240
```
241+
242+
### Errors:
243+
- Invalid or missing token
244+
- Status code: 401 Unauthorized
245+
- Response:
246+
```
247+
{
248+
"message": "invalid token, please login again",
249+
"data": ""
250+
}
251+
```

0 commit comments

Comments
 (0)