Giter VIP home page Giter VIP logo

aspnetcore-minimal-api-playground's Introduction

Minimal API Playground

A place I'm trying out the new ASP.NET Core minimal APIs for hosting and HTTP APIs.

Dependencies

Code in this repo depends on the very latest bits. If you want to try it out, grab the latest .NET 7 SDK installer.

MinimalValidation

First-class support for validation as part of the new minimal APIs is not currently planned to be implemented. However it's fairly straightforward to wire up the validation features found in System.ComponentModel.Validation through the use of a helper library (like the example this repo uses), or by using an existing validation library like FluentValidation.

Projects

Todo.Dapper

This project implements a simple Todos API including OpenAPI (Swagger) documentation and UI, and uses the Dapper library to persist data to a SQLite database.

There are some simple tests for this project in the tests/Todo.Dapper.Tests project.

Todo.EFCore

This project implements a simple Todos API including OpenAPI (Swagger) documentation and UI, and uses using Entity Framework Core to perist data to a SQLite database.

MinimalApiPlayground

This project contains numerous examples of ways to use and extend the new minimal APIs in ASP.NET Core 6/7 to build HTTP APIs.

While the Program.cs file in the project root is where the APIs are registered and implemented, much of the custom code is in the Properties directory. I keep it there as almost all .NET projects have a Properties directory and I wanted to avoid additional directories in the project to avoid any implication that additional special directories are required. Ultimately it's just code and be placed anywhere in the project.

The project includes examples of the following and more:

  • Returning strings and objects directly from APIs
  • Implementing APIs using inline anonymous lambdas, local functions, or methods
  • Using the in-framework Results and TypedResults helper classes to return common results
  • Returning custom IResult objects
  • Inferred parameter binding from route data, query-string, request body as JSON, DI container services, and HTTP request objects
  • Parameter optionality inference from parameters nullability
  • Custom parameter binding from query-string or route data values via TryParse
  • Custom async parameter binding from the request via BindAsync
  • An example extensible parameter binding object model IParameterBinder that enables creating binders for types you don't own
  • Using MVC ModelBinder implementations via a custom binding shim
  • Handling file uploads via a custom BindAsync implementation
  • Handling media types other than JSON by working directly against the incoming HttpRequest and returning a custom IResult implementation
  • Handling input validation using the MiniValidation library
  • Configuring error handling using UseExceptionHandler
  • Mutating responses from APIs via custom middleware
  • Using endpoint metadata to customize OpenAPI (Swagger) API descriptions
  • An experimental middleware for handling cross-site request forgery concerns using the framework's included IAntiforgery functionality
  • Running the framework's default inferred parameter binding logic on-demand
  • A custom set of extensions to gather metadata from the return types and parameter types in endpoint route handlers and use it to auto-describe complex route handlers to ApiExplorer without the need to manually annotate the route handlers with attributes or chained metadata method calls

aspnetcore-minimal-api-playground's People

Contributors

damianedwards avatar davidfowl avatar paulochang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.