whateverAPI is a robust, RESTful API built with .NET 9.0 that specializes in managing and serving various types of humorous content. It provides a comprehensive set of endpoints for creating, retrieving, and managing jokes with advanced features like categorization, tagging, and engagement tracking.
- β¨ Full CRUD operations for joke management
- π² Random joke retrieval with filtering options
- π·οΈ Advanced categorization system
- π Engagement tracking with laugh scores
- π Flexible search and filtering capabilities
- π Built on .NET 9.0 for optimal performance
- β‘ FastEndpoints for efficient endpoint handling
- β Comprehensive validation using FluentValidation
- π Detailed Swagger/OpenAPI documentation
- π³ Docker support for easy deployment
whateverAPI/
βββ Features/
β βββ Jokes/
β βββ CreateJoke/
β β βββ CreateJokeEndpoint.cs
β β βββ CreateJokeRequest.cs
β β βββ CreateJokeResponse.cs
β β βββ CreateJokeValidator.cs
β β βββ CreateJokeMapper.cs
β βββ GetJoke/
β β βββ GetJokeEndpoint.cs
β β βββ GetJokeRequest.cs
β β βββ GetJokeResponse.cs
β β βββ GetJokeValidator.cs
β β βββ GetJokeMapper.cs
β βββ GetJokesByType/
β β βββ [Similar structure]
β βββ GetRandomJoke/
β βββ [Similar structure]
βββ Models/
β βββ JokeEntry.cs
β βββ JokeType.cs
βββ Services/
β βββ IJokeService.cs
β βββ JokeService.cs
βββ Program.cs
POST /api/jokes
Create a new joke entry.
Request Body:
{
"content": "Why did the developer quit his job? He didn't get arrays!",
"type": "Joke",
"tags": ["programming", "work"]
}
Response (201 Created):
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"content": "Why did the developer quit his job? He didn't get arrays!",
"type": "Joke",
"tags": ["programming", "work"],
"createdAt": "2024-12-29T10:30:00Z",
"laughScore": 0
}
GET /api/jokes/random
Retrieve a random joke from the collection.
Response (200 OK):
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"content": "...",
"type": "Joke",
"tags": ["programming", "work"],
"createdAt": "2024-12-29T10:30:00Z",
"laughScore": 42
}
GET /api/jokes/type/{type}
Retrieve jokes of a specific type with optional filtering and pagination.
Parameters:
type
(path): Joke type (Joke, FunnySaying, Discouragement, SelfDeprecating)pageSize
(query, optional): Number of items per page (default: 10)pageNumber
(query, optional): Page number (default: 1)sortBy
(query, optional): Property to sort by (createdAt, laughScore, content)sortDescending
(query, optional): Sort direction (default: false)
Example:
GET /api/jokes/type/Joke?pageSize=10&pageNumber=1&sortBy=laughScore&sortDescending=true
- .NET 9.0 SDK
- Docker (optional)
- An IDE (Visual Studio 2022 or JetBrains Rider recommended)
- Clone the Repository
git clone https://github.com/yourusername/whateverAPI.git
cd whateverAPI
- Restore Dependencies
dotnet restore
- Build the Project
dotnet build
- Run the Project
dotnet run --project whateverAPI
The API will be available at:
- HTTP: http://localhost:5000
- HTTPS: https://localhost:5001
- Swagger UI: https://localhost:5001/swagger
- Build the Docker Image
docker build -t whatever-api .
- Run the Container
docker run -p 8080:80 whatever-api
- Content:
- Required
- Minimum length: 10 characters
- Maximum length: 500 characters
- Type:
- Must be a valid JokeType enum value
- Tags:
- Maximum 5 tags
- Each tag maximum length: 20 characters
- No special characters in tags
- Type:
- Must be a valid JokeType enum value
- PageSize:
- Range: 1-100
- PageNumber:
- Must be greater than 0
- SortBy:
- Must be one of: createdAt, laughScore, content
The API uses standard HTTP status codes and returns detailed error messages:
{
"errors": {
"Content": ["Content must be between 10 and 500 characters."],
"Type": ["Invalid joke type specified."],
"Tags": ["Maximum 5 tags allowed."]
}
}
Common Status Codes:
- 200: Success
- 201: Created
- 400: Bad Request (validation error)
- 404: Not Found
- 500: Internal Server Error
- Create a new feature folder under
Features/Jokes/
- Create the necessary files:
*Endpoint.cs
*Request.cs
*Response.cs
*Validator.cs
*Mapper.cs
- Implement the endpoint following the existing patterns
- Update the service layer if needed
- Add appropriate tests
- Use C# latest features and best practices
- Follow FastEndpoints conventions
- Implement proper validation
- Include XML documentation
- Add appropriate logging
Run the test suite:
dotnet test
- Unit Tests: Testing individual components
- Integration Tests: Testing endpoint behavior
- Service Tests: Testing business logic
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
- Follow the existing code style
- Add/update tests as needed
- Update documentation
- Follow conventional commits
This project is licensed under the MIT License - see the LICENSE file for details.
- FastEndpoints team for the excellent framework
- The .NET community for continuous support
- All contributors who help improve this project
For support, please open an issue in the GitHub repository or contact the maintainers.