This project is a RESTful API developed using the Rocket framework in Rust. It leverages Diesel to interact with a database populated with a sample laptop dataset sourced from Kaggle. The API provides full CRUD (Create, Read, Update, Delete) as well as query operations on the data.
Here's an example of how to use the API:
GET /laptop/<id>
Retrieve a laptop by its ID. If the laptop is found, it returns a JSON object of the laptop data, otherwise a Status::NotFound
error is returned.
GET /count
GET /laptops/search?<params..>
Search for laptops by providing search parameters, such as brand
, min_price
and max_price
.
An example API request would be like this:
localhost:8000/laptops/search?brand=Apple&min_price=1000&max_price=2000
If the search is successful, it returns a JSON array of laptop objects that match the search parameters. If there's an error, it returns a Status::InternalServerError
error.
POST /laptop
Creates a new laptop record in the database. It requires a JSON object with brand
, model
, cpu
, gpu
, ram_gb
, and price
. It returns a JSON object of the newly created laptop.
PATCH /update/<id>
Updates a laptop record in the database. It requires the ID of the laptop to update and a JSON object with brand
, model
, cpu
, gpu
, ram_gb
, and price
. If the update is successful, it returns a Status::NoContent
, otherwise a Status::InternalServerError
error.
DELETE /laptop/<id>
Deletes a laptop record from the database using its ID. If the deletion is successful, it returns a Status::NoContent
, otherwise a Status::InternalServerError
error.