Build your server with Rust using poem framework.
To build and run this project, you need the following:
- Rust: Install Rust
The project uses a specific version of Rust, which is managed automatically using rustup. Check the rust-toolchain.toml
file for the exact version.
-
Install Rust: If you don't have Rust installed, you can install it with the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Clone the Repository:
git clone https://github.com/codeitlikemiley/poem-api.git cd poem-api
-
Set the Rust Toolchain:
rustup update
-
Cargo Watch with
cargo-watch
- Install cargo-watch
cargo install cargo-watch
- Run Command:
cargo watch -x run
Note: This auto re-compiles the executable and re-run the server
-
Running the Server:
cargo run
By Default
cargo run
uses.env.example
ENV VariablePORT=3000 HOST=127.0.0.1 APP_SECRET=secret
NOTE: If you need to use other
PORT
you can pass in it as an ENV VariablePORT=8000 cargo run
-
Build Release
cargo build --release
-
Run in Production
APP_ENV=prod PORT=3001 APP_SECRET=SomeRandomString HOST=localhost ./target/release/poem-api
-
Open Swagger UI and Test the API:
open http://localhost:3000/docs
-
Login with username
{
"username": "codeitlikemiley@gmail.com"
}
![Image](https://private-user-images.githubusercontent.com/28816690/411602993-5521c2c4-a286-4254-aaa4-3344c4313b8f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2ODkyNzcsIm5iZiI6MTczOTY4ODk3NywicGF0aCI6Ii8yODgxNjY5MC80MTE2MDI5OTMtNTUyMWMyYzQtYTI4Ni00MjU0LWFhYTQtMzM0NGM0MzEzYjhmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE2VDA2NTYxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM1ZTA1YmQ3YTRkYTUzYmE5MTU0MWIyYTY3MDkxZTUxZTRhZDYzY2Q0MTFjNDkwOGQ2NTVkMWFjODg5Y2MxMjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Wx0VtI3UVdtkO2a9dQ6EQaHTouwdNM4mvtq4-k9Ltlw)
- Authorization
Copy Paste the token response from
Login
Then Go to any Locked Endpoint with a lock Icon
Click the Lock Icon , it would show a Modal , where you can paste the token
![Image](https://private-user-images.githubusercontent.com/28816690/411597061-9a1fc09d-dcb1-4133-a026-dedc4aa81c29.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2ODkyNzcsIm5iZiI6MTczOTY4ODk3NywicGF0aCI6Ii8yODgxNjY5MC80MTE1OTcwNjEtOWExZmMwOWQtZGNiMS00MTMzLWEwMjYtZGVkYzRhYTgxYzI5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE2VDA2NTYxN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEwNDQyZGRlNTFhNjgyNjNjOGZhNzdkMGUxZjQ0MmQ0N2QzNjQ4MDVlMDIwNDcyMGEyN2MyOGM1Yzc1MGFhOGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.jjLaq3Ki8uEJGkVaFlOe6Tblwz0Ou3WXe_IrFNUPX-Y)