Git Product home page Git Product logo

dotnetminimalapi's Introduction

Minimal Web APIs in .Net

Minimal APIs are architected to create HTTP APIs with minimal code footprint. They include only the minimum files, features, and dependencies. In .Net world it usually means Web APIs without use of MVC Controller subclass.

Reference

Start from scratch with Minimal API

Following commands will get you started from scratch

dotnet new sln
dotnet new webapi --use-minimal-apis -o Weatherforecast.Api
dotnet new xunit -o Weatherforecast.Tests
dotnet sln add .\Weatherforecast.Api\ .\Weatherforecast.Tests\

In case you get certificate warning execute:

dotnet dev-certs https --trust

Add dependencies if you want persistance layer

dotnet add package Microsoft.EntityFrameworkCore.InMemory
dotnet add package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore

Use Custom Templates for Minimal API in .Net

Templates which scaffold projects with Minimal API and Unit tests in .Net

dotnet new --install .\templates\

Then you can create new projects with:

dotnet new miniapihello -o HelloFeature
dotnet new miniapitodo -o TodoFeature
dotnet new miniapiauth -o EmployeeFeature

If you want to remove these project examples do:

dotnet new --uninstall .\templates\

Differences between minimal APIs and APIs with Controller subclass

  • No support for filters: For example, no support for IAsyncAuthorizationFilter, IAsyncActionFilter, IAsyncExceptionFilter, IAsyncResultFilter, and IAsyncResourceFilter.
  • No support for model binding, i.e. IModelBinderProvider, IModelBinder. Support can be added with a custom binding shim.
  • No support for binding from forms. This includes binding IFormFile. We plan to add support for IFormFile in the future.
  • No built-in support for validation, i.e. IModelValidator
  • No support for application parts or the application model. There's no way to apply or build your own conventions.
  • No built-in view rendering support. We recommend using Razor Pages for rendering views.
  • No support for JsonPatch
  • No support for OData
  • No support for ApiVersioning. See this issue for more details.

Usage in the wilds

Minimal Web API are commonly used on

Here is an example of more complex solution in .Net for Minimal API

Usage of minimal apis by packt publishing

dotnetminimalapi's People

Contributors

johnz86 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.