Skip to main content
Get your ticket management API running locally in just a few steps. This guide will walk you through cloning the repository, configuring PostgreSQL, and making your first API call.

Prerequisites

Before you begin, ensure you have the following installed:
1

Clone the Repository

Clone the ApiTickets project to your local machine:
git clone <repository-url>
cd ApiTickets
2

Create the PostgreSQL Database

Connect to your PostgreSQL server and create the database:
CREATE DATABASE "DB_tickets";
Make sure your PostgreSQL server is running on localhost with the default port 5432.
3

Configure the Connection String

Open the appsettings.json file located in the API folder and configure your PostgreSQL connection:
API/appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "Conexion": "Host=localhost;Username=postgres;Password=123456;Database=DB_tickets"
  },
  "Jwt": {
    "key": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
  }
}
Replace Username, Password, and Database with your actual PostgreSQL credentials. The JWT key should be kept secure in production environments.
Update the connection string parameters:
  • Host: Your PostgreSQL server host (default: localhost)
  • Username: Your PostgreSQL username (default: postgres)
  • Password: Your PostgreSQL password
  • Database: The database name (DB_tickets)
4

Configure CORS (Optional)

If you plan to connect a frontend application, configure the allowed origin in appsettings.Development.json:
API/appsettings.Development.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "web": "http://localhost:5173"
}
Change the web value to match your frontend application’s URL. The default is configured for a Vite/React development server.
5

Restore Dependencies

Navigate to the API project folder and restore the NuGet packages:
cd API
dotnet restore
This will install the required packages:
  • Microsoft.AspNetCore.Authentication.JwtBearer (v7.0.20)
  • Npgsql.EntityFrameworkCore.PostgreSQL
  • Swashbuckle.AspNetCore (v6.4.0)
6

Run the Application

Start the API with the following command:
dotnet run
You should see output similar to:
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5059
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
Note the port number in the output (e.g., 5059). You’ll need this to access the API and Swagger documentation.
7

Access Swagger Documentation

Open your browser and navigate to the Swagger UI:
http://localhost:5059/swagger/index.html
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.
8

Make Your First API Call

Test the login endpoint to verify everything is working correctly.

Using cURL

curl -X POST "http://localhost:5059/api/usuario/login" \
  -H "Content-Type: application/json" \
  -d '{
    "correo": "[email protected]",
    "password": "yourpassword"
  }'

Using Swagger UI

  1. Navigate to the Usuarios section
  2. Click on POST /api/usuario/login
  3. Click Try it out
  4. Enter the request body:
{
  "correo": "[email protected]",
  "password": "yourpassword"
}
  1. Click Execute

Response

A successful login will return a JWT token in the response:
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "usuario": {
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "correo": "[email protected]",
    "nombre": "John Doe"
  }
}
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

Ensure that:
  • PostgreSQL is running on your machine
  • The database DB_tickets exists
  • Your credentials in appsettings.json are correct
  • The PostgreSQL server is accepting connections on localhost:5432
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 is only enabled in Development mode. Ensure you’re running the application with the Development environment:
dotnet run --environment Development
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.

Project Structure

The ApiTickets project follows Clean Architecture principles:
ApiTickets/
├── API/                    # Web API layer (controllers, startup)
├── Application/            # Application logic and services
├── Domain/                 # Domain entities and DTOs
├── Infrastructure/         # External services and implementations
└── Persistence/           # Database context and repositories
The main application entry point is in API/Program.cs, where services, CORS, authentication, and middleware are configured.

Build docs developers (and LLMs) love