{"id":21559791,"url":"https://github.com/dasiths/simpleendpoints","last_synced_at":"2025-04-10T11:41:11.115Z","repository":{"id":86599569,"uuid":"246319788","full_name":"dasiths/SimpleEndpoints","owner":"dasiths","description":"A simple, convention-based, endpoint per action pattern implementation for AspNetCore 3.0+ with full support for Swagger","archived":false,"fork":false,"pushed_at":"2020-04-01T14:05:28.000Z","size":132,"stargazers_count":36,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T10:22:01.993Z","etag":null,"topics":["api","aspnetcore","clean-architecture","controller","convention","endpoints","nuget","openapi","swagger"],"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/dasiths.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-03-10T14:15:46.000Z","updated_at":"2025-02-22T22:27:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"123daab6-1060-47b2-92e5-3d4f06f88ff5","html_url":"https://github.com/dasiths/SimpleEndpoints","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasiths%2FSimpleEndpoints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasiths%2FSimpleEndpoints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasiths%2FSimpleEndpoints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dasiths%2FSimpleEndpoints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dasiths","download_url":"https://codeload.github.com/dasiths/SimpleEndpoints/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248210884,"owners_count":21065630,"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","aspnetcore","clean-architecture","controller","convention","endpoints","nuget","openapi","swagger"],"created_at":"2024-11-24T09:09:27.518Z","updated_at":"2025-04-10T11:41:11.094Z","avatar_url":"https://github.com/dasiths.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleEndpoints ![Build Master](https://github.com/dasiths/SimpleEndpoints/workflows/Build%20Master/badge.svg?branch=master) [![NuGet](https://img.shields.io/nuget/v/SimpleEndpoints.svg)](https://www.nuget.org/packages/SimpleEndpoints) [![Downloads](https://img.shields.io/nuget/dt/SimpleEndpoints.svg)](https://www.nuget.org/packages/SimpleEndpoints/)\n \n ### A simple, convention-based, endpoint per action pattern implementation for AspNetCore 3.0+\n \n\u003cimg src=\"./assets/logo.png\" alt=\"Logo\" width=\"200\"/\u003e\n\n## Motivation\n\nThe aim of this pattern is to get away from the bloated god controllers that have a million action methods and so many dependencies. By following the SimpleEndpoints pattern we keep the endpoint scoped to a small feature and lightweight which makes it easier to understand and manage. The aim is not to blur the line between the controllers and the domain layer. You can choose to dispatch the request to the domain from the endpoint or handle it in the endpoint itself. Make an informed choice based to the context.\n\nMore about it in the [blog post here](https://dasith.me/2020/03/21/simple-endpoints/).\n\n## Getting Started\n\n1. Install and reference the Nuget `SimpleEndpoints`\n\nIn the NuGet Package Manager Console, type:\n\n```\n    Install-Package SimpleEndpoints\n```\n\n2. Define your request and response models\n```C#\n    public class SimpleMessage\n    {\n        public string Message { get; set; }\n    }\n\n    public class SimpleResponse\n    {\n        public string Message { get; set; }\n    }\n```\n3. Create your endpoint and implement your business logic (You can choose to handle in place or dispatch to a domain layer)\n```C#\n    public class SimpleMessageEndpoint : AsyncGetEndpoint\u003cSimpleMessage, SimpleResponse\u003e\n    {\n        public override async Task\u003cActionResult\u003cSimpleResponse\u003e\u003e HandleAsync(SimpleMessage requestModel, CancellationToken cancellationToken = default)\n        {\t\n\t    // Handle in place or dispatch to the domain i.e. return await _someDomainService.HandleAsync(requestModel)\n\t\n            return new SimpleResponse()\n            {\n                Message = \"Hello \" + requestModel.Message\n            };\n        }\n    }\n```\n4. In the `ConfigureServices()` method in your `Startup.cs` add the following\n```C#\n    public void ConfigureServices(IServiceCollection services)\n    {\n        // Other services go here\n\t\t\n        services.AddControllers();\n        services.AddSimpleEndpointsRouting(); // This is required to translate endpoint names\n    }\n```\n\n5. Navigate to the URL `https://localhost:port_number/simplemessage?message=world` and see the result.\n\n---\n\n## Want more ?\n\nCheckout the [Examples folder](https://github.com/dasiths/SimpleEndpoints/tree/master/src/SimpleEndpoints.Example) for more. Await more examples in the coming weeks.\n\nThe Endpoints are automatically inherited from a [`ControllerBase`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase?view=aspnetcore-3.1) and decorated with [`ApiController` attribute](https://www.strathweb.com/2018/02/exploring-the-apicontrollerattribute-and-its-features-for-asp-net-core-mvc-2-1/). You can decorate the endpoint class/action method with the usual (Route, HttpGet, FromQuery etc) attributes to customise and extend the functionality. Endpoints fully support [AspNetCore routing conventions](https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-3.1).\n\nIf you really need an endpoint with a custom route, a mix of parameters coming from the Route/Query/Body or need full control over of any aspect then you can do something like this. Each of these class/method attributes works independently of each other and you can pick and choose them as required.\n\n```c#\n    [SimpleEndpoint(HttpVerb.Get)] // define the HTTP method being used\n    [Route(\"custom/[endpoint]\")] // use your own route template (i.e this results in \"custom/mysimple\")\n    public class MySimpleEndpoint : SimpleEndpointBase // Extend the SimpleEndpointBase class\n    {\n        // definew your custom signature binding attributes\n        [Route(\"custom-method\")]\n        public ActionResult\u003cGreetingResponse\u003e MyMethodName([FromQuery] int id, [FromBody] GreetingRequest requestModel) // Mix of binding attributes\n        {\n            return new GreetingResponse()\n            {\n                Greeting = $\"Hello {requestModel.name} with id {id}\"\n            };\n        }\n    }\n```\n\nI've had good success with creating a folder structure like below.\n\n![Folder Structure](/assets/simple-ednpoints-folderstructure.png)\n\nYou can take this one step further and create a **folder per feature group**, then put each endpoint specific folder inside that if you want as well. I recommend keeping the view models in the same folder as it's easier to find related code when they sit next to each other.\n\n---\n\nFeel free to contribute and raise issues as you see fit :)\n\n- Creator: Dasith Wijesiriwardena (https://dasith.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdasiths%2Fsimpleendpoints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdasiths%2Fsimpleendpoints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdasiths%2Fsimpleendpoints/lists"}