Prerequisites
Before you begin, ensure you have the following installed:- .NET 7 SDK
- PostgreSQL (any recent version)
- Git
- A code editor (Visual Studio, VS Code, or Rider)
Create the PostgreSQL Database
Connect to your PostgreSQL server and create the database:
Make sure your PostgreSQL server is running on
localhost with the default port 5432.Configure the Connection String
Open the Update the connection string parameters:
appsettings.json file located in the API folder and configure your PostgreSQL connection:API/appsettings.json
- Host: Your PostgreSQL server host (default:
localhost) - Username: Your PostgreSQL username (default:
postgres) - Password: Your PostgreSQL password
- Database: The database name (
DB_tickets)
Configure CORS (Optional)
If you plan to connect a frontend application, configure the allowed origin in
appsettings.Development.json:API/appsettings.Development.json
Change the
web value to match your frontend application’s URL. The default is configured for a Vite/React development server.Restore Dependencies
Navigate to the API project folder and restore the NuGet packages:This will install the required packages:
- Microsoft.AspNetCore.Authentication.JwtBearer (v7.0.20)
- Npgsql.EntityFrameworkCore.PostgreSQL
- Swashbuckle.AspNetCore (v6.4.0)
Access Swagger Documentation
Open your browser and navigate to the Swagger UI:Replace
5059 with your actual port number from the previous step.Swagger provides an interactive interface to explore and test all available API endpoints. In development mode, Swagger is automatically enabled.
Make Your First API Call
Test the login endpoint to verify everything is working correctly.
Using cURL
Using Swagger UI
- Navigate to the Usuarios section
- Click on
POST /api/usuario/login - Click Try it out
- Enter the request body:
- Click Execute
Response
A successful login will return a JWT token in the response:You’ll need to create users in your database before you can log in. The authentication endpoint is defined in
API/Controllers/UsuariosController.cs:19-24.What’s Next?
Now that your API is running, explore these resources:Authentication
Learn how JWT authentication works and how to use bearer tokens
API Endpoints
Explore all available endpoints for managing tickets
Database Schema
Understand the PostgreSQL database structure and relationships
Configuration
Deep dive into configuration options and environment variables
Troubleshooting
Database connection failed
Database connection failed
Ensure that:
- PostgreSQL is running on your machine
- The database
DB_ticketsexists - Your credentials in
appsettings.jsonare correct - The PostgreSQL server is accepting connections on
localhost:5432
Port already in use
Port already in use
If port 5059 is already in use, .NET will automatically select another port. Check the console output for the actual port number, or specify a custom port in
launchSettings.json.Swagger page not loading
Swagger page not loading
Swagger is only enabled in Development mode. Ensure you’re running the application with the Development environment:
CORS errors from frontend
CORS errors from frontend
Make sure the frontend URL is correctly configured in
appsettings.Development.json under the web property. The CORS configuration is set up in API/Program.cs:15-21.