{"id":23810091,"url":"https://github.com/vlada22/minimal-api-slim-endpoints","last_synced_at":"2025-09-06T18:32:23.110Z","repository":{"id":65217338,"uuid":"588235799","full_name":"vlada22/minimal-api-slim-endpoints","owner":"vlada22","description":"MinimalApi SlimEndpoints","archived":false,"fork":false,"pushed_at":"2023-01-16T09:10:22.000Z","size":31,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-01T17:55:57.201Z","etag":null,"topics":["dotnet","endpoints","minimalapi","slim-endpoints","source-generators"],"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/vlada22.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-12T16:41:51.000Z","updated_at":"2024-11-28T13:12:58.000Z","dependencies_parsed_at":"2023-02-10T02:16:26.258Z","dependency_job_id":null,"html_url":"https://github.com/vlada22/minimal-api-slim-endpoints","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlada22%2Fminimal-api-slim-endpoints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlada22%2Fminimal-api-slim-endpoints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlada22%2Fminimal-api-slim-endpoints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vlada22%2Fminimal-api-slim-endpoints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vlada22","download_url":"https://codeload.github.com/vlada22/minimal-api-slim-endpoints/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232137185,"owners_count":18477785,"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":["dotnet","endpoints","minimalapi","slim-endpoints","source-generators"],"created_at":"2025-01-02T00:12:09.888Z","updated_at":"2025-01-02T00:12:10.559Z","avatar_url":"https://github.com/vlada22.png","language":"C#","readme":"# MinimalApi Slim Endpoints\n![Github actions](https://github.com/vlada22/minimal-api-slim-endpoints/actions/workflows/build-release.yml/badge.svg)\n[![Nuget feed](https://img.shields.io/nuget/v/MinimalApi.SlimEndpoints?label=MinimalApi.SlimEndpoints)](https://www.nuget.org/packages/MinimalApi.SlimEndpoints)\n\nSmall library for decoupling endpoints in [MinimalApi] from the Program.cs file.\n\nThis library does not add any additional overhead to the application, it just helps you to organize your code better.\n\nThe source generator will generate a DependencyInjection extension that will contain all the endpoints that you have defined in your application.\n\n## Installation\nInstall the package from NuGet:\n```bash\ndotnet add package MinimalApi.SlimEndpoints\n```\n\n## Quick start\n\nCreate a class that inherits from `ISlimEndpoint` and implement the `Configure` and `Handler` methods. Add the `SlimEndpoint` attribute to the class.\n\n### SlimEndpoint attribute\nThe `SlimEndpoint` attribute has the following properties:\n- `Path` - The path of the endpoint. This is the same as the `MapGet` method in the `MinimalApi`.\n- `HttpMethod` - The HTTP method of the endpoint. This is the same as the `MapGet` method in the `MinimalApi`.\n\n### Configure method\nThe `Configure` method injects the `RouteHandlerBuilder` into the endpoint class. Leave the method empty if you don't need to configure the endpoint.\n\n### Handler method\nThe `Handler` method is the main method of the endpoint. It is called when the endpoint is hit.\n\n### Example\n```csharp\nusing MinimalApi.SlimEndpoints.Abstractions;\n\nnamespace SampleDemo.Endpoints;\n\n[SlimEndpoint(Path = \"/hello\", Method = \"GET\")]\npublic partial class HelloEndpoint : ISlimEndpoint\n{\n    public void Configure(RouteHandlerBuilder builder)\n    {\n        builder.AllowAnonymous();\n    }\n\n    public Delegate Handler =\u003e (() =\u003e \"Hello World!\");\n}\n```\n\n## Dependency Injection configuration\nThe `MinimalApi.SlimEndpoints` library uses the `Microsoft.Extensions.DependencyInjection` library for dependency injection. You can configure the DI container in the `Program.cs` file.\n```csharp\nvar builder = WebApplication.CreateBuilder(args);\n\n// Register endpoints\nbuilder.Services.AddSlimEndpoints();\n\nvar app = builder.Build();\n\n// Map endpoints\napp.MapSlimEndpoints();\n\napp.Run();\n```\n\n## Common pitfalls\nPlease do not capture any services in the `Handler` method that are injected into the endpoint class. Instead, inject the services into the `Handler` method directly.\n\nInjected services into the endpoint class should only be used in the `Configure` method.\n\n❌ **BAD** This example uses a service that is injected into the endpoint class.\n```csharp\n[SlimEndpoint(Path = \"/hello\", Method = \"GET\")]\npublic partial class HelloEndpoint : ISlimEndpoint\n{\n    private readonly ExampleService _service;\n    \n    public HelloEndpoint(ExampleService service)\n    {\n        _service = service;\n    }\n\n    public void Configure(RouteHandlerBuilder builder)\n    {\n        builder.AllowAnonymous();\n    }\n\n    public Delegate Handler =\u003e (() =\u003e _service.GetExample());\n}\n```\n\n✅ **GOOD** This example injects the service directly into the `Handler` method.\n```csharp\n[SlimEndpoint(Path = \"/hello\", Method = \"GET\")]\npublic partial class HelloEndpoint : ISlimEndpoint\n{\n    public void Configure(RouteHandlerBuilder builder)\n    {\n        builder.AllowAnonymous();\n    }\n\n    public Delegate Handler =\u003e ((ExampleService service) =\u003e service.GetExample());\n}\n```\n\n**Note**: Please see the [SampleDemo](./samples/SampleDemo) project for a complete example.\n\n## Change log\nPlease see the [CHANGELOG](./CHANGELOG.md) for more information on what has changed recently.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n\n[MinimalApi]: https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-4/#introducing-minimal-apis\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvlada22%2Fminimal-api-slim-endpoints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvlada22%2Fminimal-api-slim-endpoints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvlada22%2Fminimal-api-slim-endpoints/lists"}