DotEmilu 2.0.1

dotnet add package DotEmilu --version 2.0.1
                    
NuGet\Install-Package DotEmilu -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotEmilu" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotEmilu" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="DotEmilu" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotEmilu --version 2.0.1
                    
#r "nuget: DotEmilu, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=DotEmilu&version=2.0.1
                    
Install DotEmilu as a Cake Addin
#tool nuget:?package=DotEmilu&version=2.0.1
                    
Install DotEmilu as a Cake Tool

DotEmilu

A simple, easy-to-use .NET library designed for handling HTTP requests and responses.

Features

  • Supports GET, POST, PUT, and DELETE requests.
  • Handles HTTP responses with status codes and error handling.
  • Built with .NET 8 for cross-platform compatibility (Windows, Linux, macOS).
  • Supports async/await for non-blocking HTTP calls.
  • Includes request contracts and base constraints for verifiers.
  • Provides an HttpHandler to simplify request handling.
  • New extension method to register handlers using reflection for cleaner setup.

How to Use

Follow these simple steps to get started:

  1. Build Your Logic
    Create the logic for your application based on your previously defined request and expected response.

    public class FullUseCase(
        IVerifier<FullDto> verifier,
        IVerifier<InDto> verifierIn,
        IHandler<InDto> handlerIn)
        : Handler<FullDto, FullOutDto>(verifier)
    {
        private readonly IVerifier<FullDto> _verifier = verifier;
    
        protected override async Task<FullOutDto?> HandleUseCaseAsync(FullDto request, CancellationToken cancellationToken)
        {
            Console.WriteLine("Handling my primary use case...");
    
            var requestIn = new InDto(request.Day);
    
            await WorksSecondCaseAsync(requestIn, cancellationToken);
    
            if (!verifierIn.IsValid)
            {
                _verifier.AddErrors(verifierIn.Errors.ToList());
                _verifier.AddError("BehindCase", "Second case has errors");
                return null;
            }
    
            return new FullOutDto();
        }
    
        private async Task WorksSecondCaseAsync(InDto request, CancellationToken cancellationToken)
            => await handlerIn.HandleAsync(request, cancellationToken);
    }
    
  2. Add Your Endpoint
    Define your endpoint using either Minimal API or a Controller, depending on your project's structure.

        private static async Task<IResult> FullCase([FromBody] FullDto dto,
            HttpHandler<FullDto, FullOutDto> handler,
            CancellationToken cancellationToken)
            => await handler.HandleAsync(dto, cancellationToken, _ => Results.NoContent());
    
  3. Register Your Dependencies
    Ensure all required dependencies are registered in your application's dependency injection container.

    builder.Services
        .AddDotEmilu()
        .AddHandlers(Assembly.GetExecutingAssembly())
        .AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
    

For a complete example

Notes:

You need to add the response messages for bad request (400) and server error (500)

{
  "ResultMessage": {
    "ValidationError": {
      "Title": "Bad Request",
      "Detail": "One or more errors"
    },
    "ServerError": {
      "Title": "Server Error",
      "Detail": "Please contact to administrator"
    }
  }
}

And for complex validation use fluent validation

public class SampleValidator : AbstractValidator<SampleRequest>
{
    public SampleValidator()
    {
        RuleFor(s => s.Date)
            .GreaterThanOrEqualTo(DateOnly.FromDateTime(DateTime.Now));

        RuleFor(s => s.Amount)
            .GreaterThan(0);
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DotEmilu:

Package Downloads
DotEmilu.AspNetCore

Simple .NET library to handle http requests in AspNetCore

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 140 3/31/2025
2.0.0 99 3/28/2025
1.0.3 110 2/18/2025
1.0.2 110 2/18/2025
1.0.1 100 2/4/2025
1.0.0 90 1/13/2025

Refactored the project to only accept a generic handler without external dependencies.