Basic api for car rentals to study the Rust language
- The Rust programming language
- A PostgreSQL database
- Clone the project
- Run the command
mv .env.example .env
to rename the.env.example
file to.env
- Fill in with the environment variables in the
.env
file - Run the database migrations with the command
cargo run --bin migrate
- Run the server with the command
cargo run --bin rust-car-rental-api
- PORT: The port you want the server to run in. Example:
4000
(defaults to 8080) - DATABASE_URL: A string with the information to connect to the database. Example:
postgres:https://postgres:postgres@localhost:5432/rust_car_rental
- JWT_SECRET: A secret string to use to hash the jwt. Example:
uidgqw78dgqw78giodcqwuih
All application routes
GET /brands
used to get the list of all brandsPOST /brands
used to create a new brand- name
[string, required]
- name
GET /brands/:id
used to get a brand by idPUT /brands/:id
used to update a brand by id- name
[string, required]
- name
DELETE /brands/:id
used to delete a brand by id
GET /cars
used to get the list of all carsPOST /cars
used to create a new car- brand_id
[uuid, required]
- model
[string, required]
- horse_power
[int, required]
- torque_in_lb
[float, required]
- top_speed_in_km
[int, required]
- acceleration_speed_in_km
[float, required]
- weight_in_kg
[int, required]
- rental_price_daily_in_usd
[float, required]
- brand_id
GET /cars/:id
used to get a car by idPUT /cars/:id
used to update a car by id- brand_id
[uuid, required]
- model
[string, required]
- horse_power
[int, required]
- torque_in_lb
[float, required]
- top_speed_in_km
[int, required]
- acceleration_speed_in_km
[float, required]
- weight_in_kg
[int, required]
- rental_price_daily_in_usd
[float, required]
- brand_id
DELETE /cars/:id
used to delete a car by id
POST /auth/register
used to register new user- name
[string, required]
- email
[string, required]
- password
[string, required]
- name
POST /auth/login
used to login- email
[string, required]
- password
[string, required]
- email
GET /auth/me
used to get logged in user data[requires auth]
GET /rentals
used to get the list of all rentals- car_id - if specified it will return only the rentals for this car_id
[optional]
- starts_at - if specified it will return only the rentals that have a starts_at greater than or equal to the specified date
[optional]
- ends_at - if specified it will return only the rentals that have an ends_at lesser than or equal to the specified date
[optional]
- car_id - if specified it will return only the rentals for this car_id
GET /rentals/mine
used to get the list of all rentals from logged user[requires auth]
- car_id - if specified it will return only the rentals for this car_id
[optional]
- starts_at - if specified it will return only the rentals that have a starts_at greater than or equal to the specified date
[optional]
- ends_at - if specified it will return only the rentals that have an ends_at lesser than or equal to the specified date
[optional]
- car_id - if specified it will return only the rentals for this car_id
POST /rentals
used to rent a car[requires auth]
- car_id - The id of the car you want to rent
[required]
- starts_at - The start date for which you want to rent the car
[required]
- ends_at - The end date for which you want to rent the car
[required]
- car_id - The id of the car you want to rent
PATCH /rentals/:id/cancel
used to cancel a rental[requires auth]
The /auth/register
and the /auth/login
endpoints return an access_token
, send it as a Bearer token in the request, as the Authorization header, for example: Bearer access_token_here