Skip to content

amg262/whateverAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

whateverAPI - A Joke Management API. or whatever

whateverAPI

Overview

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.

Features

Core Functionality

  • ✨ 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

Technical Features

  • πŸš€ 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

Project Structure

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

API Endpoints

Create Joke

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 Random Joke

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 Jokes By Type

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

Setup and Installation

Prerequisites

  • .NET 9.0 SDK
  • Docker (optional)
  • An IDE (Visual Studio 2022 or JetBrains Rider recommended)

Local Development Setup

  1. Clone the Repository
git clone https://github.com/yourusername/whateverAPI.git
cd whateverAPI
  1. Restore Dependencies
dotnet restore
  1. Build the Project
dotnet build
  1. Run the Project
dotnet run --project whateverAPI

The API will be available at:

Docker Setup

  1. Build the Docker Image
docker build -t whatever-api .
  1. Run the Container
docker run -p 8080:80 whatever-api

Validation Rules

Create Joke Validation

  • 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

Get Jokes By Type Validation

  • 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

Error Handling

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

Development Guidelines

Adding a New Endpoint

  1. Create a new feature folder under Features/Jokes/
  2. Create the necessary files:
    • *Endpoint.cs
    • *Request.cs
    • *Response.cs
    • *Validator.cs
    • *Mapper.cs
  3. Implement the endpoint following the existing patterns
  4. Update the service layer if needed
  5. Add appropriate tests

Code Style

  • Use C# latest features and best practices
  • Follow FastEndpoints conventions
  • Implement proper validation
  • Include XML documentation
  • Add appropriate logging

Testing

Run the test suite:

dotnet test

Test Categories

  • Unit Tests: Testing individual components
  • Integration Tests: Testing endpoint behavior
  • Service Tests: Testing business logic

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contribution Guidelines

  • Follow the existing code style
  • Add/update tests as needed
  • Update documentation
  • Follow conventional commits

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • FastEndpoints team for the excellent framework
  • The .NET community for continuous support
  • All contributors who help improve this project

Support

For support, please open an issue in the GitHub repository or contact the maintainers.

About

whatever bruh. A portable joke API on .NET 9

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published