A .NET 9 REST API for managing wedding invitations with MongoDB storage.
- Full CRUD operations for wedding invitations
- Template, font, and content management
- MongoDB database with ObjectId support
- Input validation with FluentValidation
- Comprehensive error handling and logging
- Rate limiting with AspNetCoreRateLimit
- CORS support
- Swagger/OpenAPI documentation
- Dependency injection and clean architecture
- .NET 9.0 SDK
- MongoDB running on localhost:27017
- Visual Studio 2022 or VS Code (optional)
- Navigate to the project directory:
cd dotnetcode- Restore dependencies:
dotnet restore
- Build the project:
dotnet build
- Run the application:
dotnet run
For development with hot reload:
dotnet watch run
GET /api/wedding-invitations- Get all wedding invitationsPOST /api/wedding-invitations- Create a new wedding invitationGET /api/wedding-invitations/{id}- Get wedding invitation by IDPUT /api/wedding-invitations/{id}- Update wedding invitationDELETE /api/wedding-invitations/{id}- Delete wedding invitation
GET /api/wedding-invitations/{id}/template- Get template configurationPUT /api/wedding-invitations/{id}/template- Update template configurationGET /api/templates- Get all available templates
GET /api/wedding-invitations/{id}/fonts- Get font configurationPUT /api/wedding-invitations/{id}/fonts- Update font configuration
GET /api/wedding-invitations/{id}/content- Get content detailsPUT /api/wedding-invitations/{id}/content- Update content details
GET /api/wedding-invitations/{id}/content/basic-info- Get basic informationPUT /api/wedding-invitations/{id}/content/basic-info- Update basic informationGET /api/wedding-invitations/{id}/content/ceremony-details- Get ceremony detailsPUT /api/wedding-invitations/{id}/content/ceremony-details- Update ceremony detailsGET /api/wedding-invitations/{id}/content/additional-info- Get additional informationPUT /api/wedding-invitations/{id}/content/additional-info- Update additional information
The application can be configured through appsettings.json:
{
"MongoDbSettings": {
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "barunson",
"CollectionName": "wedding"
},
"IpRateLimiting": {
"EnableEndpointRateLimiting": true,
"GeneralRules": [
{
"Endpoint": "*",
"Period": "15m",
"Limit": 100
}
]
}
}ASPNETCORE_ENVIRONMENT- Set toDevelopmentfor development modeASPNETCORE_URLS- Specify the URLs for the application (e.g.,https://localhost:5001;http://localhost:5000)
The API uses MongoDB to store wedding invitation data:
- Database:
barunson - Collection:
wedding - Connection:
mongodb://localhost:27017
MongoDB documents are structured according to the wedding invitation schema with proper BSON attributes and ObjectId support.
Swagger UI documentation is available at multiple endpoints:
/docs- Main documentation endpoint (redirects to Swagger UI)/swagger- Direct Swagger UI access/- Root URL (redirects to Swagger UI)
URLs:
https://localhost:5001/docs(HTTPS)http://localhost:5000/docs(HTTP)
Visit /health to check if the API is running:
curl http://localhost:5000/health
curl -X POST https://localhost:5001/api/wedding-invitations \ -H "Content-Type: application/json" \ -d '{ "template": { "opening_effect": { "enabled": false, "lettering_effect": { "enabled": true, "color": "#000000", "position": "center" } }, "design": { "template_id": "default", "frame": { "type": "square", "options": ["square", "arch", "circle"] }, "photo": { "url": "", "required": true }, "colors": { "background": "#ffffff", "accent": "#000000" } } }, "fonts": { "title": { "family": "default", "color": "#000000", "size": "S", "size_options": ["S", "M", "L"] }, "body": { "family": "default", "color": "black", "color_options": ["black", "white"], "size": "S", "size_options": ["S", "M", "L"] } }, "content": { "basic_info": { "groom": { "name": "John Doe", "max_length": 20, "required": true }, "bride": { "name": "Jane Smith", "max_length": 20, "required": true }, "relationship": "사랑하는 두 사람" }, "ceremony_details": { "date": "2024-06-15", "time": "14:00", "venue": { "name": "Garden Wedding Hall", "address": "123 Wedding St, Seoul", "contact": "02-1234-5678" } }, "additional_info": { "parents": { "groom_parents": { "father": "John Doe Sr.", "mother": "Mary Doe" }, "bride_parents": { "father": "Robert Smith", "mother": "Lisa Smith" } }, "message": "함께 해주셔서 감사합니다", "contact_info": { "phone": "010-1234-5678", "email": "wedding@example.com" } } }, "metadata": { "created_date": "", "last_modified": "", "version": "1.0", "language": "ko" } }'
The application follows clean architecture principles:
- Controllers: Handle HTTP requests and responses
- Services: Business logic and orchestration
- Models: Data models and entities
- DTOs: Data transfer objects for API responses
- Validators: Input validation using FluentValidation
- Middleware: Cross-cutting concerns (error handling, logging)
The API includes rate limiting to prevent abuse:
- 100 requests per 15 minutes per IP
- 500 requests per hour per IP
All errors are handled consistently and return standardized error responses:
{
"success": false,
"error": "Error message here",
"data": null,
"message": null
}The application uses built-in .NET logging with different log levels:
Information: General application flowWarning: Potentially harmful situationsError: Error events that might still allow the application to continueDebug: Fine-grained informational events (Development only)
- Add method to the appropriate service interface
- Implement the method in the service class
- Add controller action
- Add validation if needed
- Update Swagger documentation
dotnet testdotnet format
For production deployment:
- Set
ASPNETCORE_ENVIRONMENT=Production - Configure appropriate logging levels
- Set up MongoDB connection string for production
- Configure reverse proxy (nginx/IIS) if needed
- Enable HTTPS
- Ensure MongoDB is properly secured and backed up
- Microsoft.AspNetCore.OpenApi - OpenAPI support
- Swashbuckle.AspNetCore - Swagger UI
- FluentValidation.AspNetCore - Input validation
- MongoDB.Driver - MongoDB .NET driver
- MongoDB.Bson - BSON serialization
- Newtonsoft.Json - JSON serialization
- AspNetCoreRateLimit - Rate limiting
- Microsoft.Extensions.Logging - Logging
This repository includes:
- ✅ Source code (
.cs,.csprojfiles) - ✅ Configuration templates (
appsettings.json,appsettings.Development.json) - ✅ Documentation (
README.md) - ✅ Project configuration (
Program.cs, validators, models, etc.)
The following files/folders are automatically excluded:
- ❌ Build artifacts (
bin/,obj/,dist/) - ❌ IDE files (
.vs/,.vscode/,.idea/) - ❌ User-specific settings (
*.user,*.suo) - ❌ Production secrets (
appsettings.Production.json,secrets.json) - ❌ Logs and temporary files
- ❌ Database files (
*.db,*.sqlite) - ❌ Environment variables (
.envfiles)
- MongoDB connection strings in
appsettings.jsonuse localhost (safe for development) - Production configurations should be stored separately and not committed
- API keys, passwords, and sensitive data should use environment variables or Azure Key Vault in production
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
MIT License