Skip to content

juniorporfirio/NET5_MinimalApi_With_Carter

Repository files navigation

NET5 Minimal Api with Carter

It's example i am show, who is possible does one Web Api using "Minimal Api" using Carter

Features

Example with Carter

This is some example using Carter on .NET5.

Get - Super Heros

Returning one list of Super Heros

Get("/superhero", async (request, response) =>
               await response.WriteAsJsonAsync(superHero)
            );

Get - Super Hero per Id

Returning one Super Hero per id

Get("superhero/{id}", async (request, response) =>{
                var id = request.RouteValues.As<Guid>("id");
                await response.WriteAsJsonAsync(superHero.First());
            });

POST - New Super Hero with Validation(FluentValidation)

Returning the new Super Hero created

Post("/superhero", async (req, res) =>
            {
                var hero = await req.Bind<SuperHero>();
                var validate = req.Validate(hero);
                if (validate.IsValid)
                {
                    res.StatusCode = 201;
                    await res.WriteAsJsonAsync(hero);
                }

                res.StatusCode = 400;
                res.ContentType = "application/problem+json";
                await res.WriteAsJsonAsync(validate.GetFormattedErrors());
            });

About

Example the WebApi with .NET5 using package Carter

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages