By Aaron Minnick, Jacob Wilson, Christina Welch, and Hannah Young
This web API is designed to model a train transportation system with management and routefinding endpoints. There are stations that are connected via tracks and the ability to find routes along those stations and tracks.
- C#
- .NET
- MySQL
- Entity Framework
- Swagger / OpenAPI
This is a web API that showcases our ability to develop an ASP.NET Core API with a robust backend attached to a MySQL database through Entity Framework. Routefinding is performed through graph algorithms, including depth first search.
- Download and install the .NET 6.0 SDK as required for your system. Be sure to add the .NET sdk to your PATH
- Use terminal to navigate to desired parent directory and use
git clone https://github.com/Corgibyte/trains.git Trains.Solution - Navigate into the project directory nested inside the .Solution directory:
cd Trains.Solution/Trains - Create an appsettings.json file:
touch appsettings.json - Edit the new appsettings.json file and add the following, making sure to replace the indicated sections with your MySQL user ID and password:
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Port=3306;database=trains_api;uid=[YOUR MYSQL USER ID];pwd=[YOUR MYSQL PASSWORD];"
}
}
- Back in the terminal, in the Trains directory build the project:
dotnet restore - Create database from migration data:
dotnet ef database update - Run project:
dotnet run
API endpoints can be accessed using a client such as Postman or programatically using your own client. Endpoint testing can also be performed on the Swagger documentation accessed at http://localhost:5000/swagger
| Usage | METHOD | URL | Params |
|---|---|---|---|
| Get all routes from origin to destination | GET | http://localhost:5000/api/Routes/AllRoutesBetween |
origin :int, destination :int, sortMethod†: time or fare |
| Get fastest route to all destinations from origin | GET | http://localhost:5000/api/Routes/AllDestinationsFrom |
origin :int |
| Get all Stations | GET | http://localhost:5000/api/stations |
|
| Get specific Station | GET | http://localhost:5000/stations/{id} |
|
| Create Station | POST | http://localhost:5000/stations/ |
Station :schema* |
| Edit Station | PUT | http://localhost:5000/stations/{id} |
Station :schema* |
| Delete Station | DELETE | http://localhost:5000/stations/{id} |
|
| Get all Tracks | GET | http://localhost:5000/api/tracks |
origin† :int, destination† :int |
| Get specific Track | GET | http://localhost:5000/tracks/{id} |
|
| Create Track | POST | http://localhost:5000/tracks/ |
Track :schema* |
| Edit Track | PUT | http://localhost:5000/tracks/{id} |
Track :schema* |
| Delete Track | DELETE | http://localhost:5000/tracks/{id} |
*See below for example schemas for Stations and Tracks †Optional filtering parameter
Station:
"Station": {
"required": [
"name"
],
"type": "object",
"properties": {
"stationId": {
"type": "integer",
"format": "int32"
},
"name": {
"maxLength": 20,
"minLength": 0,
"type": "string"
}
},
"additionalProperties": false
}
Track:
"Track": {
"type": "object",
"properties": {
"trackId": {
"type": "integer",
"format": "int32"
},
"originId": {
"type": "integer",
"format": "int32"
},
"destinationId": {
"type": "integer",
"format": "int32"
},
"origin": {
"$ref": "#/components/schemas/Station"
},
"destination": {
"$ref": "#/components/schemas/Station"
},
"travelTime": {
"type": "integer",
"format": "int32"
},
"fare": {
"type": "number",
"format": "double"
}
},
"additionalProperties": false
}
- None
Hippocratic License 3.0, Copyright 2022 Aaron Minnick, Jacob Wilson, Christina Welch, and Hannah Young.