A Rusty Rocket 🚀 fuelled with Diesel 🛢 and secured by JWT 🔐
You can build and run app from source:
Or using Docker
- Install Rust nightly (Thanks for Rustup 1.20!):
rustup install nightly
- Set Rust Nightly to project: Go to the root of the project, open cmd/terminal and run
rustup override set nightly
- Rename
secret.key.sample
tosecret.key
or create your own key by runninghead -c16 /dev/urandom > secret.key
in command line (Linux/UNIX only) and copy to/src
folder - Create a database in postgres cli or pgAdmin tool
- Rename
Rocket.toml.sample
toRocket.toml
and update the database connection string inurl
key. - Build with release profile:
cargo build --release
- Run release binary in command line/terminal. On Windows:
target/release/address_book_rest_api.exe
, on *UNIX:target/release/address_book_rest_api
- Enjoy! 😄
- Enter into project directory and run
docker-compose up
- Enjoy! 😄
- Request body:
{
"username": string,
"email": string,
"password": string // a raw password
}
- Response
- 200 OK
{ "message": "signup successfully", "data": "" }
- 400 Bad Request
{ "message": "error when signing up, please try again", "data": "" }
- Request body:
{
"username_or_email": string,
"password": string // a raw password
}
- Response
- 200 OK
{ "message": "login successfully", "data": { "token": string // bearer token } }
- 400 Bad Request
{ "message": "wrong username or password, please try again", "data": "" }
- Header:
- Authorization: bearer <token>
- Response
- 200 OK
{ "message": "ok", "data": [ { "id": int32, "name": string, "gender": boolean, // true for male, false for female "age": int32, "address": string, "phone": string, "email": string } ] }
- Param path:
- id: int32
- Header:
- Authorization: bearer <token>
- Response
- 200 OK
{ "message": "ok", "data": { "id": int32, "name": string, "gender": boolean, // true for male, false for female "age": int32, "address": string, "phone": string, "email": string } }
- 404 Not Found
{ "message": "person with id {id} not found", "data": "" }
- Param path:
- query: string
- Header:
- Authorization: bearer <token>
- Response
- 200 OK
{ "message": "ok", "data": [ { "id": int32, "name": string, "gender": boolean, // true for male, false for female "age": int32, "address": string, "phone": string, "email": string } ] }
- Header:
- Authorization: bearer <token>
- Request body:
{ "name": string, "gender": boolean, // true for male, false for female "age": int32, "address": string, "phone": string, "email": string }
- Response
- 201 Created
{ "message": "ok", "data": "" }
- 500 Internal Server Error
{ "message": "can not insert data", "data": "" }
- Param path:
- id: int32
- Header:
- Authorization: bearer <token>
- Request body:
{
"name": string,
"gender": boolean, // true for male, false for female
"age": int32,
"address": string,
"phone": string,
"email": string
}
- Response
- 200 OK
{ "message": "ok", "data": "" }
- 500 Internal Server Error
{ "message": "can not update data", "data": "" }
- Param path:
- id: int32
- Header:
- Authorization: bearer <token>
- Response
- 200 OK
{ "message": "ok", "data": "" }
- 500 Internal Server Error
{ "message": "can not delete data", "data": "" }
- Invalid or missing token
- Status code: 401 Unauthorized
- Response:
{ "message": "invalid token, please login again", "data": "" }