This project is linked to the presentation available at: https://docs.google.com/presentation/d/1c1mFfeYFlwrpy_DwFGpHq0F4GRCDfG0-X-tbIWMHBvU/edit?usp=sharing
This project is a RESTful API for managing car/automobile data, built with Ktor framework. It provides endpoints for retrieving and creating car information.
ws://127.0.0.1:8080/echo ws://127.0.0.1:8080/echoShared ws://127.0.0.1:8080/echoSerial
Technology | Purpose |
---|---|
Ktor | Lightweight web framework for Kotlin |
Exposed | SQL framework for database access |
H2 Database | In-memory database for development |
Koin | Dependency injection framework |
kotlinx.serialization | JSON serialization/deserialization |
Swagger | API documentation |
Endpoint | Method | Description |
---|---|---|
/auto |
GET | Retrieve all cars |
/auto/{id} |
GET | Retrieve a specific car by ID |
/auto/init |
GET | Initialize a new car with random data (for testing) |
Endpoint | Method | Description |
---|---|---|
/cliente |
GET | Retrieve all clients |
/cliente/{id} |
GET | Retrieve a specific client by ID |
/cliente |
POST | Create a new client |
Endpoint | Method | Description |
---|---|---|
/noleggio |
GET | Retrieve all rentals |
/noleggio/{id} |
GET | Retrieve a specific rental by ID |
/noleggio |
POST | Create a new rental |
Endpoint | Method | Description |
---|---|---|
/echo |
WebSocket | Echo WebSocket endpoint |
/echoShared |
WebSocket | Shared Echo WebSocket endpoint |
/echoSerial |
WebSocket | Serial Echo WebSocket endpoint |
- JDK 17 or higher
- Gradle
- Clone the repository
- Navigate to the project directory
- Run the application:
./gradlew run
The server will start on http://0.0.0.0:8080
.
Once the application is running, you can access the Swagger UI at:
http://localhost:8080/openapi
To build or run the project, use one of the following tasks:
Task | Description |
---|---|
./gradlew test |
Run the tests |
./gradlew build |
Build everything |
buildFatJar |
Build an executable JAR of the server with all dependencies included |
buildImage |
Build the docker image to use with the fat JAR |
publishImageToLocalRegistry |
Publish the docker image locally |
run |
Run the server |
runDocker |
Run using the local docker image |
If the server starts successfully, you'll see the following output:
2024-12-04 14:32:45.584 [main] INFO Application - Application started in 0.303 seconds.
2024-12-04 14:32:45.682 [main] INFO Application - Responding at http://0.0.0.0:8080
- Follow the Kotlin Coding Conventions
- Use meaningful names for classes, functions, and variables
- Write comments for complex logic
- Keep functions small and focused on a single responsibility
- Place DTOs in the
model
package - Place database entities in the
tables
package - Place repositories in the
repository
package - Place routing logic in the
routing
package
- Define the data model in the
model
package - Create database tables in the
tables
package - Implement repository methods in the
repository
package - Define API endpoints in the
routing
package - Update the OpenAPI documentation
- Write unit tests for repositories and services
- Write integration tests for API endpoints
- Run tests before submitting changes:
./gradlew test