I blogged about the open source Carter Community Project in 2019. Let’s check in and see what’s going on today in 2021! With .NET 6 on the near horizon, one notes that Carter has a net6 branch. Per their website, this is the goal of the Carter framework:
As of today you can bring Carter into your .NET 6 projects like this: dotnet add package Carter --version 6.0.0-pre2 And the .NET 6 samples are under active development! Let’s bring it down with a clone, switch to the net6 branch and give it a go. Here’s as simple Web API sample with Carter that returns a list of actors at localhost:5001/actors using Carter; Nice! This is using new .NET 6 features so there’s no Main(), it’s implied. The builder has an ActorProvider added as a Singleton. I bet we’ll use that when we ask for /actors in our browser or favorite HTTP API client. public class ActorsModule : ICarterModule This is nice and clean. Everything is using Dependency Injection so no one is “newing up” an Actor. You’ll note also that returning the Actors as JSON is implied when we return the IEmumerable<Actor> that comes from actorProvider.Get(). In fact, the whole Actor Module is just 80 lines so I’ll include it here: public class ActorsModule : ICarterModule Note the API example at /actors/download that shows how to return a file like an MP4. Nice and simple. This sample also includes thoughtful validation code with FluentValidation extension methods like ctx.Request.Validate(). Carter is opinionated but surprisingly flexible. You can use two different routing APIs, or clean and performant Endpoint routing: this.Get("/", (req, res) => res.WriteAsync("There's no place like 127.0.0.1")).RequireAuthorization(); It even supports OpenAPI out of the box! Carter has an active Slack as well as Templates you can add to make your next File | New Project easier! dotnet new -i CarterTemplate There’s a lot of great innovation happening in the .NET open source space right now. ![]() Carter is just one cool example. Go check out Carter on GitHub, give them a Star, try it out and get involved in open source! Sponsor: YugabyteDB is a distributed SQL database designed for resilience and scale. It is 100% open source, PostgreSQL-compatible, enterprise-grade, and runs across all clouds. Sign up and get a free t-shirt © 2021 Scott Hanselman. All rights reserved. Carter Community for ASP.NET Core means enjoyable Web APIs on the cutting edge published first on http://7elementswd.tumblr.com/ via Tumblr Carter Community for ASP.NET Core means enjoyable Web APIs on the cutting edge
0 Comments
Leave a Reply. |
About UsIf you want to keep up with the latest in web design, you have to be willing to study and learn on an ongoing basis. If you are a web developer or web designer, you’ll find a lot of useful tutorials and code snippets collection here. Furthermore, we also discuss more general topics of web design and how the role of a web designer has evolved over the years.
|