Skip to content

imclint21/Initium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

129 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Initium

Initium

Service Core Foundation for .NET API development.

Introduction

Initium is a library for simplifying .NET API development, offering standardized service operations, flexible routing, and seamless chaining of service results for cleaner and more maintainable code.

  • Streamlined API Controllers: Simplifies response handling with attributes like [ApiResponse], providing clear and consistent HTTP status documentation.
  • Centralized Result Management: ServiceResult enables clear success or failure status, making error handling and conditional logic seamless.
  • Exception Handling Made Easy: ApiException provides a straightforward way to handle specific HTTP error codes, improving code clarity.
  • Result Chaining: Methods return ServiceResult or typed results, allowing for intuitive chaining and cleaner service logic.
  • Enhanced Maintainability: Standardized patterns reduce boilerplate code, making APIs easier to build, understand, and maintain.

Getting Started

To get started with Initium, just add the package using NuGet:

dotnet add package Initium

How does it Work?

Here's how to create a controller :

public class CoffeeController(CoffeeService service) : ApiController
{
    [HttpPost]
    [ApiResponse(200, "Coffee prepared successfully.")]
    [ApiResponse(400, "An error occurred during the preparation process.")]
    public ActionResult PrepareCoffee() => service.PrepareCoffee();
}

And here's how to create an action in a service, each function returns a ServiceResult, and can be chained.

public class CoffeeService
{
    public ServiceResult DoSomething()
    {
        return ServiceResult.Error("Something happened!", HttpStatusCode.Conflict);
    }

    public ServiceResult PrepareCoffee()
    {
        var doSomethingResult = DoSomething();
        if (doSomethingResult == false) return doSomethingResult;

        return ServiceResult.Ok("The coffee is now DONE!");
    }
}

Documentation

See the docs/ folder for detailed documentation:

Contribute to Initium

See CONTRIBUTING.md for best practices and instructions on setting up your development environment to work on Initium.

About

Initium is a .NET library that simplifies building APIs by standardizing service management, routing, and response handling.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages