I would like to share with you a tiny preconfigured template to create amazing apis with Rust, using routes, json and so on.
api_folder\
|- main.rs
|- routes.rs
|- models.rs
First check you have already Rust installed.
Clone this repositorio Git
Run cargo check cargo run
git clone https://github.com/ricardodarocha/sqlxpg.git
cd sqlxpg
cargo run
Navigate to
GET localhost:8089/user
This server is preconfigured in port 8089
This server has the following routes
/ping
/pong
/user
/post_user
https://github.com/ricardodarocha/sqlxpg/blob/master/src/api/routes.rs
The Postgre database connection is seted in https://github.com/ricardodarocha/sqlxpg/blob/master/src/main.rs
Models represent the struct of sql, tables em views https://github.com/ricardodarocha/sqlxpg/blob/master/src/model/usermodel.rs
The models implemments FromRow do serialization