Skip to content

Commit 41d3389

Browse files
committed
Update README
1 parent 6e2d7e7 commit 41d3389

File tree

1 file changed

+84
-3
lines changed

1 file changed

+84
-3
lines changed

README.md

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
# Actix-web REST API
1+
# Actix-web REST API with JWT
22

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

55
# Require
66

77
- [Rust Stable](https://rustup.rs)
8+
- [Postgres](https://www.postgresql.org/)
89

910
# How to run
1011

11-
- Build and run project: `cargo run`
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
13+
- Create a database in postgres cli or [pgAdmin](https://www.pgadmin.org/) tool
14+
- Rename `.env.sample` to `.env` and update the database connection string in `DATABASE_URL` key.
15+
- Build with release profile: `cargo build --release`
16+
- Run release binary in command line/terminal.
17+
- Windows: `target/release/address_book_rest_api.exe`
18+
- Linux/UNIX: `target/release/address_book_rest_api`
1219
- Enjoy! 😄
1320

1421
# APIs
@@ -23,7 +30,60 @@ A simple backend app using Actix-web
2330
pong!
2431
```
2532
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+
2684
### `GET /api/address-book`: Get all people information
85+
- Header:
86+
- Authorization: bearer \<token\>
2787
- Response
2888
- 200 OK
2989
```
@@ -46,6 +106,8 @@ A simple backend app using Actix-web
46106
### `GET /api/address-book/{id}`: Get person information by id
47107
- Param path:
48108
- id: int32
109+
- Header:
110+
- Authorization: bearer \<token\>
49111
- Response
50112
- 200 OK
51113
```
@@ -73,6 +135,8 @@ A simple backend app using Actix-web
73135
### `GET /api/address-book/{query}`: Search for person information by keyword
74136
- Param path:
75137
- query: string
138+
- Header:
139+
- Authorization: bearer \<token\>
76140
- Response
77141
- 200 OK
78142
```
@@ -93,6 +157,8 @@ A simple backend app using Actix-web
93157
```
94158
95159
### `POST /api/address-book`: Add person information
160+
- Header:
161+
- Authorization: bearer \<token\>
96162
- Request body:
97163
```
98164
{
@@ -123,6 +189,8 @@ A simple backend app using Actix-web
123189
### `PUT /api/address-book/{id}`: Update person information by id
124190
- Param path:
125191
- id: int32
192+
- Header:
193+
- Authorization: bearer \<token\>
126194
- Request body:
127195
```
128196
{
@@ -153,6 +221,8 @@ A simple backend app using Actix-web
153221
### `DELETE /api/address-book/{id}`: Delete person information by id
154222
- Param path:
155223
- id: int32
224+
- Header:
225+
- Authorization: bearer \<token\>
156226
- Response
157227
- 200 OK
158228
```
@@ -168,3 +238,14 @@ A simple backend app using Actix-web
168238
"data": ""
169239
}
170240
```
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)