VerticalApi 2023.3.13.225321

There is a newer version of this package available.
See the version list below for details.
dotnet add package VerticalApi --version 2023.3.13.225321                
NuGet\Install-Package VerticalApi -Version 2023.3.13.225321                
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="VerticalApi" Version="2023.3.13.225321" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VerticalApi --version 2023.3.13.225321                
#r "nuget: VerticalApi, 2023.3.13.225321"                
#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.
// Install VerticalApi as a Cake Addin
#addin nuget:?package=VerticalApi&version=2023.3.13.225321

// Install VerticalApi as a Cake Tool
#tool nuget:?package=VerticalApi&version=2023.3.13.225321                

Introduction

VerticalApi is intended to be a simple implementation of Vertical slicing and Minimal Api at the same time.
By allowing simplistic folder structure and a minimal amount of boilerplate code it creates an easy way to setup individual endpoints and maintaining them over time.

Setup

Mapping endpoints

In the following example all endpoints relevant to public access will be mapped.
This is done by setting the property NamespaceRoot to endpoints/public.
The setting will map all found endpoints contained in the ApplicationNameSpace.endpoints.public

app.MapEndpoints(new EndpointOptions()
{
  NamespaceRoot = "endpoints/public",
  ApiBasePath = "api/public",
});

Endpoint Options

NameSpaceRoot:

Reflects the root of the namespace desired to be mapped.

Example: ApplicationNamespace.Area.Endpoints can be mapped with area/endpoints
Example: ApplicationNamespace.Endpoints.Public can be mapped with endpoints/public

ApiBasePath:

Sets the base path for the mapped endpoint.
Example: api/public will become https://domain.com/api/public/*
Example: endpoints/public will become https://domain.com/endpoints/public/*

RequireAuthorization:

If endpoints in the mapping should be authorized, set this to true.
It is necessary for app.UseAuthorization() to be called before mapping for authorization to be enabled.
Note: The [AllowAnonymous] attribute will override the authorization requirement on individual endpoints

AuthenticationScheme:

Set the desired authentication scheme that should apply to the given endpoints. Note: Requires the RequireAuthorization attribute to be enabled, as well as app.UseAuthentication()

CorsPolicyName:

Sets the name for the Cors policy to be used with the mapped endpoints.
Note: Requires app.UseCors() to be set.

Endpoint file

The endpoint file will consist of a class containing one or more methods that can be mapped as endpoints.
These methods must always be public and static in order for them to be mapped.
Everything else is considered private methods.

namespace SolutionName.Endpoints.Public.Articles;

[Endpoint]
public static class GetByIdEndpoint {
  
  public static async Task<Article> Get(
    [FromRoute] int Id,
    [FromServices] DataContext context,
    CancellationToken cancellationToken) 
  {
  
    var article = await context.Articles.FirstAsync(article => article.Id == Id, cancellationToken);
  
    return article;
  }
}

Folder structure

One of the intentions for VerticalApi is to simplify folder structures and assist in making it easier to create a simple edition of vertical slicing.
Below is an example of how a folder structure could be set up.

  SolutionName
    - Endpoints
      - Public
        - Articles
          - GetById
            | GetById.cs
            - Dtos
              | GetByIdResponse.cs
            - Tests
              | GetByIdTest.cs

The structure allows for segmentation of the endpoint logic from the DTOs, Mappers, Helpers and other logic that ties in closely to the endpoint.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2023.11.14.1420 205 11/14/2023
2023.11.13.235409 140 11/13/2023
2023.11.13.234435 141 11/13/2023
2023.11.13.232646 141 11/13/2023
2023.11.13.204258 131 11/13/2023
2023.5.12.124206 2,083 5/12/2023
2023.5.10.133233 195 5/10/2023
2023.5.10.121207 169 5/10/2023
2023.3.13.232329 523 3/13/2023
2023.3.13.231248 228 3/13/2023
2023.3.13.225321 238 3/13/2023
2023.1.12.131146 1,591 1/12/2023
2022.12.20.190400 314 12/20/2022
2022.11.27.173018 362 11/27/2022
2022.11.27.172008 345 11/27/2022
2022.11.27.170711 345 11/27/2022
2022.11.27.165443 335 11/27/2022
2022.11.26.153242 338 11/26/2022
2022.6.10.233509 2,086 6/10/2022
2022.6.10.222549 430 6/10/2022
2022.3.18.162630 454 3/18/2022