This is an API developed in C# with ASP.NET Core for managing cities and students. The system allows bulk importing of all Brazilian cities (2026) from a CSV file into a MySQL database, CRUD operations for cities, and student management with support for photo upload and Base64 conversion. The entire infrastructure is orchestrated via Docker.
Developed to fulfill the assignment proposed by the Programming Languages course - 1st Term, 2026.
- C# / ASP.NET Core: Main Web API framework.
- MySQL: Relational database for persisting cities and students.
- Docker: Containerization and orchestration of the API and the Database.
- Swagger/OpenAPI: Interactive documentation and endpoint testing.
The project was divided into three main parts:
- Import city data via
.csvfile upload directly into the database. - Batch processing support (
usarLoteparameter) for large files. - CRUD operations (Create, Read, Update, Delete) for cities.
- Filters and aggregations: total city count, state listing, and city filtering by specific state.
- Registration and querying of student entities linked to cities.
- Upload endpoint to receive image files (student photo) via
multipart/form-data. - Viewing endpoint that returns the stored student photo encoded as a Base64 string.
- The API implements the OpenAPI standard, providing the Swagger interface for querying and testing all contracts and routes.
Below is a summary of the routes exposed by the application.
| Method | Route | Description |
|---|---|---|
POST |
/importar |
Imports cities from a .csv file (supports usarLote=true). |
GET |
/api/cidades |
Returns all registered cities. |
POST |
/api/cidades |
Manually inserts a new city. |
GET |
/api/cidades/{id} |
Returns details of a specific city by ID. |
PUT |
/api/cidades/{id} |
Updates data of an existing city. |
DELETE |
/api/cidades/{id} |
Deletes a city by ID. |
GET |
/total |
Returns the total count of registered cities. |
GET |
/estados |
Returns the list of all registered states (UFs). |
GET |
/estado/{uf} |
Returns a list of cities filtered by state abbreviation. |
| Method | Route | Description |
|---|---|---|
POST |
/Alunos |
Creates a new student record. |
GET |
/Alunos/{id} |
Retrieves a student record by ID. |
POST |
/Alunos/{id}/foto |
Receives and stores the student's photo via form-data. |
GET |
/Alunos/{id}/foto |
Returns the student's photo encoded in Base64 format. |
Note: A sample file (cidade.csv) is located at the root of this project for import testing.
For the /importar endpoint, the .csv file must contain the following column structure (with header row):
- CidadeId: Unique city identifier (Int).
- Nome: City name (String).
- Sigla: State abbreviation / UF (String).
- IBGEMunicipio: IBGE city code (Int).
- Latitude: City latitude (Double/Decimal).
- Longitude: City longitude (Double/Decimal).
- Clone the repository:
git clone https://github.com/mateus-sm/WebAPI.git
The entire project infrastructure, including MySQL table initialization and creation, is automated with Docker.
-
Start the containers:
Make sure you have Docker Desktop (or Docker Engine) running on your machine.
In the terminal, at the project root (where thedocker-compose.ymlfile is located), run:docker-compose up -d --build
Docker will download the MySQL image, create the
cidades_dbdatabase viainit.sql, and start the services. -
Access the API:
With the containers running, start the C# project via Visual Studio or your preferred method.
Open the browser and navigate to the URL mapped to the/docroute.
Terminal output when running the project:info: Microsoft.Hosting.Lifetime[14] Now listening on: http://localhost:5182 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: C:\WebAPIIn the example above, access would be at: http://localhost:5182/doc