{"id":18296511,"url":"https://github.com/shadynagy/microendpoints","last_synced_at":"2025-06-28T13:32:42.059Z","repository":{"id":163991714,"uuid":"639332765","full_name":"ShadyNagy/MicroEndpoints","owner":"ShadyNagy","description":"\"MicroEndpoints is a .NET library built to streamline the creation of HTTP endpoints using .NET 6's Minimal APIs. By offering both synchronous and asynchronous operations, it enhances the development experience of lightweight HTTP APIs.","archived":false,"fork":false,"pushed_at":"2025-03-03T08:50:16.000Z","size":1032,"stargazers_count":6,"open_issues_count":6,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-22T23:14:48.959Z","etag":null,"topics":["api","endpoint","endpoints","microendpoints","minimal","minimal-api","net6","net7"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShadyNagy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-11T08:56:29.000Z","updated_at":"2025-03-03T08:50:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"77ebe70a-e1de-451f-8dc6-3cc817327542","html_url":"https://github.com/ShadyNagy/MicroEndpoints","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ShadyNagy/MicroEndpoints","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadyNagy%2FMicroEndpoints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadyNagy%2FMicroEndpoints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadyNagy%2FMicroEndpoints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadyNagy%2FMicroEndpoints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShadyNagy","download_url":"https://codeload.github.com/ShadyNagy/MicroEndpoints/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShadyNagy%2FMicroEndpoints/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262438085,"owners_count":23311081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","endpoint","endpoints","microendpoints","minimal","minimal-api","net6","net7"],"created_at":"2024-11-05T14:41:19.458Z","updated_at":"2025-06-28T13:32:42.023Z","avatar_url":"https://github.com/ShadyNagy.png","language":"C#","funding_links":["https://github.com/sponsors/ShadyNagy"],"categories":[],"sub_categories":[],"readme":"[![publish to nuget](https://github.com/ShadyNagy/MicroEndpoints/actions/workflows/nugt-publish.yml/badge.svg)](https://github.com/ShadyNagy/MicroEndpoints/actions/workflows/nugt-publish.yml)\n[![MicroEndpoints on NuGet](https://img.shields.io/nuget/v/MicroEndpoints?label=MicroEndpoints)](https://www.nuget.org/packages/MicroEndpoints/)\n[![NuGet](https://img.shields.io/nuget/dt/MicroEndpoints)](https://www.nuget.org/packages/MicroEndpoints)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/ShadyNagy/MicroEndpoints/blob/main/LICENSE)\n[![Sponsor](https://img.shields.io/badge/Sponsor-ShadyNagy-brightgreen?logo=github-sponsors)](https://github.com/sponsors/ShadyNagy)\n\n\n# MicroEndpoints\n\nMicroEndpoints is a .NET library that simplifies creating HTTP endpoints in a minimalistic and clean manner. It's designed to work with .NET 6's Minimal APIs. \n\nMinimal APIs in .NET 6 offer an easy way to build HTTP APIs with the flexibility to add more features as your project grows. They are great for creating HTTP APIs where you typically send and receive HTTP requests and responses. These APIs are often used with single-page apps, mobile clients, and for public HTTP APIs.\n\nHere are a few benefits of Minimal APIs:\n\n- Simplicity: With Minimal APIs, you can use a single line of code to express an API endpoint, making it easy to understand.\n- Productivity: Minimal APIs require less code and less ceremony, which leads to a productivity gain.\n- Performance: Minimal APIs are built on top of the same high-performance components as the rest of ASP.NET Core.\n\nFor more detailed information, please refer to the [Microsoft Documentation on Minimal APIs](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-6.0).\n\nWith MicroEndpoints, you can leverage the simplicity and performance of Minimal APIs with a structured and easy-to-use model, making your development process even more efficient.\n\n\n## Getting Started\n\nTo install the library, you can use the .NET CLI:\n\n```shell\ndotnet add package MicroEndpoints\n```\n\nAfter installing the package, make sure to include the following line in your `Program.cs`:\n\n```csharp\n//...\nbuilder.Services.AddMicroEndpoints(Assembly.GetAssembly(typeof(Program)));\n//...\nvar app = builder.Build();\n//...\napp.UseMicroEndpoints();\n\napp.Run();\n```\n\n# Endpoint Types\n\nMicroEndpoints provides the flexibility to create synchronous or asynchronous endpoints based on your application's needs. \n\n## Synchronous Endpoints\n\nIf you don't have any I/O-bound work that would benefit from asynchrony, you can create synchronous endpoints. Here's an example:\n\n```csharp\npublic class MySyncEndpoint : EndpointBaseSync\n    .WithRequest\u003cMyRequest\u003e\n    .WithIResult\n{\n  public override IResult Handle(MyRequest request)\n  {\n    // Implementation...\n  }\n}\n```\n\nIn the example above, `MySyncEndpoint` is a synchronous endpoint that handles a `MyRequest` request and returns an `IResult`.\n\n## Asynchronous Endpoints\n\nIf you're performing I/O-bound operations, such as network requests or database queries, you should use asynchronous endpoints. Here's an example:\n\n```csharp\npublic class MyAsyncEndpoint : EndpointBaseAsync\n    .WithRequest\u003cMyRequest\u003e\n    .WithIResult\n{\n  public override async Task\u003cIResult\u003e HandleAsync(MyRequest request, CancellationToken cancellationToken = default)\n  {\n    // Implementation...\n  }\n}\n```\n\nIn this example, `MyAsyncEndpoint` is an asynchronous endpoint that handles a `MyRequest` request and returns an `IResult`.\n\n# Endpoint Results\n\nThe result of an endpoint can be of any type. However, it's recommended to use `IResult` for its flexibility and expressiveness. `IResult` allows you to easily produce different HTTP responses.\n```csharp\npublic class MyEndpoint : EndpointBaseAsync\n    .WithoutRequest\n    .WithIResult\n{\n  [Get(\"api/authors\")]\n  public override async Task\u003cIResult\u003e HandleAsync(CancellationToken cancellationToken = default)\n  {\n    // Implementation...\n    return Ok();\n  }\n}\n```\n\nIf you want to return a custom type, you can do so by specifying the type when inheriting from `EndpointBaseAsync` or `EndpointBaseSync`. Here's an example:\n\n```csharp\npublic class MyEndpoint : EndpointBaseAsync\n    .WithRequest\u003cMyRequest\u003e\n    .WithResult\u003cMyResponse\u003e // MyResponse is a custom class\n{\n  public override async Task\u003cMyResponse\u003e HandleAsync(MyRequest request, CancellationToken cancellationToken = default)\n  {\n    // Implementation...\n  }\n}\n```\n\nIn the example above, `MyEndpoint` is an asynchronous endpoint that handles a `MyRequest` request and returns a `MyResponse` result.\n\n# Dependency Injection\n\nIf you need to use services from the dependency injection (DI) container in your endpoints, you can do so within the `Handle` or `HandleAsync` methods. \n\nYou can use the `GetService` method from the `IServiceProvider` to retrieve your services. Here's an example:\n\n```csharp\npublic override async Task\u003cIResult\u003e HandleAsync([FromServices] IServiceProvider serviceProvider, MyRequest request, CancellationToken cancellationToken = default)\n{\n  // Get services from the DI container\n  _repository = serviceProvider.GetService\u003cIAsyncRepository\u003cAuthor\u003e\u003e()!;\n  _mapper = serviceProvider.GetService\u003cIMapper\u003e()!;\n\n  // Implementation...\n}\n```\n\nIn the example above, `IAsyncRepository\u003cAuthor\u003e` and `IMapper` are being retrieved from the service provider, which is injected into the method by the framework.\n\nRemember to add a reference to the `Microsoft.Extensions.DependencyInjection` namespace to use the `GetService` method.\n\n# How to Use\n\nMicroEndpoints provides a base class `EndpointBaseAsync` that you can inherit from to define your own endpoints. Here's how you can use it:\n\n```csharp\npublic class Get : EndpointBaseAsync\n      .WithRequest\u003cint\u003e\n      .WithIResult\n{\n  //...\n}\n```\n\nIn this example, the `Get` class is an endpoint that expects a request with an integer parameter and returns an `IResult` type. The actual handling of the request is done in the `HandleAsync` method which needs to be overridden.\n\n# Examples\nHere are some examples:\n\n### Get Endpoint\n\n```csharp\npublic class Get : EndpointBaseAsync\n      .WithRequest\u003cint\u003e\n      .WithIResult\n{\n  private IAsyncRepository\u003cAuthor\u003e _repository;\n  private IMapper _mapper;\n\n  public Get(IAsyncRepository\u003cAuthor\u003e repository, IMapper mapper)\n  {\n    _repository = repository;\n    _mapper = mapper;\n  }\n\n  [Get(\"api/authors/{id}\")]\n  public override async Task\u003cIResult\u003e HandleAsync([FromServices] IServiceProvider serviceProvider, int id, CancellationToken cancellationToken = default)\n  {\n    // Implementation...\n  }\n}\n```\n\n### Post Endpoint\n\n```csharp\npublic class Create : EndpointBaseAsync\n    .WithRequest\u003cCreateAuthorCommand\u003e\n    .WithIResult\n{\n  private IAsyncRepository\u003cAuthor\u003e _repository;\n  private IMapper _mapper;\n\n  public Create(IAsyncRepository\u003cAuthor\u003e repository, IMapper mapper)\n  {\n    _repository = repository;\n    _mapper = mapper;\n  }\n\n  [Post(\"api/authors\")]\n  public override async Task\u003cIResult\u003e HandleAsync([FromServices] IServiceProvider serviceProvider, [FromBody] CreateAuthorCommand request, CancellationToken cancellationToken = default)\n  {\n    // Implementation...\n  }\n}\n```\n\n### Put Endpoint\n\n```csharp\npublic class Create : EndpointBaseAsync\n    .WithRequest\u003cCreateAuthorCommand\u003e\n    .WithIResult\n{\n  private IAsyncRepository\u003cAuthor\u003e _repository;\n  private IMapper _mapper;\n\n  public Create(IAsyncRepository\u003cAuthor\u003e repository, IMapper mapper)\n  {\n    _repository = repository;\n    _mapper = mapper;\n  }\n\n  [Put(\"api/authors\")]\n  public override async Task\u003cIResult\u003e HandleAsync([FromServices] IServiceProvider serviceProvider, [FromBody] CreateAuthorCommand request, CancellationToken cancellationToken = default)\n  {\n    // Implementation...\n  }\n}\n```\n\n### Delete Endpoint\n\n```csharp\npublic class Delete : EndpointBaseAsync\n    .WithRequest\u003cint\u003e\n    .WithIResult\n{\n  private IAsyncRepository\u003cAuthor\u003e _repository;\n\n  public Delete(IAsyncRepository\u003cAuthor\u003e repository)\n  {\n    _repository = repository;\n  }\n\n  [Delete(\"api/authors/{id:int}\")]\n  public override async Task\u003cIResult\u003e HandleAsync([FromServices] IServiceProvider serviceProvider, [FromRoute] int id, CancellationToken cancellationToken = default)\n  {\n    // Implementation...\n  }\n}\n```\n\nYou can see more examples in the [examples](https://github.com/ShadyNagy/MicroEndpoints/tree/main/tests/MicroEndpoints.EndpointApp) directory.\n\n# Acknowledgements\n\nWe would like to express our gratitude towards [Ardalis (Steve Smith)](https://github.com/ardalis) for creating the [Ardalis.Endpoints](https://github.com/ardalis/ApiEndpoints) package. His work served as an inspiration and provided a solid foundation for the development of MicroEndpoints. \n\nWe highly recommend checking out his [package](https://github.com/ardalis/ApiEndpoints) and other [contributions](https://github.com/ardalis) to the .NET community.\n\n\n## Contributing\n\nWe welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details.\n\n## License\n\nThis project is licensed under the terms of the MIT license. See the [LICENSE](./LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadynagy%2Fmicroendpoints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshadynagy%2Fmicroendpoints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadynagy%2Fmicroendpoints/lists"}