Prerequisites
Before you begin, ensure you have the following installed:You can verify your .NET installation by running
dotnet --version in your terminal.Quick Setup
Configure PostgreSQL Connection
Update the database connection string in
appsettings.json:appsettings.json
Configure JWT Settings
Update the JWT configuration in
appsettings.json with your own secure key:appsettings.json
The JWT key should be at least 32 characters for HMACSHA256 security.
Configure Client Credentials
Set up your client application credentials in
appsettings.json:appsettings.json
Run the Application
Start the API server:You should see output indicating:
- Migrations are being applied
- Database is created (if it doesn’t exist)
- Default admin user is created
- API is listening on ports (typically http://localhost:5000 and https://localhost:5001)
Your First API Request
Let’s make your first authenticated request to the API.Step 1: Obtain a JWT Token
Authenticate using the default admin credentials:The token is valid for 60 minutes by default. Save this token for subsequent requests.
Step 2: Create Your First Project
Use the JWT token to create a photography project:Step 3: Retrieve Projects
Fetch all active projects (no authentication required):Database Management
View Database Tables
Connect to your PostgreSQL database to verify the setup:Reset Database
If you need to reset the database:Development Tips
Hot Reload
Hot Reload
Use The application will automatically restart when you modify source files.
dotnet watch run for automatic reload during development:View Logs
View Logs
Logs are written to the console by default. Adjust logging levels in
appsettings.json:Testing with Swagger
Testing with Swagger
Use Swagger UI for interactive testing:
- Navigate to
http://localhost:5000/swagger - Click “Authorize” button
- Enter:
Bearer YOUR_TOKEN - Click “Authorize” to save
- Test endpoints directly from the UI
Multiple Client Applications
Multiple Client Applications
Add more client credentials in Restart the API after modifying configuration.
appsettings.json:Troubleshooting
Database Connection Failed
Database Connection Failed
Error:
Connection refused or password authentication failedSolution:- Verify PostgreSQL is running:
systemctl status postgresql(Linux) or check Services (Windows) - Check connection string credentials match your PostgreSQL setup
- Ensure PostgreSQL is listening on port 5432:
netstat -an | grep 5432
Migration Errors
Migration Errors
Error:
A connection was successfully established, but an error occurred during the login processSolution:- Delete the
Migrationsfolder - Drop the database:
dropdb -U postgres XgpPhotoDb - Run the application again to recreate migrations
JWT Token Invalid
JWT Token Invalid
Error:
401 Unauthorized when making authenticated requestsSolution:- Verify the token hasn’t expired (60 minute default)
- Ensure you’re including the
Bearerprefix:Authorization: Bearer YOUR_TOKEN - Check that the JWT Key in
appsettings.jsonmatches between login and validation
Client Credentials Invalid
Client Credentials Invalid
Error:
Unauthorized: Invalid client credentialsSolution:- Verify
ClientIdandClientSecretmatch exactly what’s inappsettings.json - Check for typos and ensure case sensitivity
- Restart the API after modifying client credentials
Next Steps
Now that you have the API running, explore these topics:Authentication Guide
Learn about JWT tokens and client validation
API Reference
Detailed documentation of all endpoints
Working with Projects
Understanding project management and data models
Deployment
Deploy to production environments