Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting started with minimal apis end to end #34011

Closed
3 tasks
Tracked by #34010 ...
LadyNaggaga opened this issue Jul 1, 2021 · 0 comments
Closed
3 tasks
Tracked by #34010 ...

Getting started with minimal apis end to end #34011

LadyNaggaga opened this issue Jul 1, 2021 · 0 comments
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@LadyNaggaga
Copy link

LadyNaggaga commented Jul 1, 2021

This issue intends to capture a smooth getting started experience with minimal APIs. Our goal is to have all experience smoothed (😺 ) out before we will move the new minimal api template from a package to OOB with the SDK.

Current user Experience Description
😺 Smooth experience
😾 Bumpy experience
🙀 Confusing / Overwhelming experience
🎩 Stretch goal for the product
✔️ Available in the empty template OOB. No additional configuration required from the developer

Acquisition

Note : To try out minimal APIs for hosting and routing in web applications we announced in .NET 6 preview 4 today, create a new ASP.NET Core empty web app dotnet new web -o MinApi. ✔️

  • Phase 1: Minimal APIs template as a package

  • Install package Microsoft.AspNetCore.Minimal-api.Templates
    dotnet new install Microsoft.AspNetCore.MinimalApi.Templates:: 0.1.0-pre

  • Create a new minimal api
    dotnet new api -o myapi

  • Phase 2: New minimal APIs template shipped in .NET SDK

  • User installs .NET SDK

  • API template surfaces in the .NET CLI and Visual Studio new project dialogue.

Define a new endpoint ✔️ 😺

  • User can easily define a new endpoint

app.MapGet("/foo", () => "I am new endpoint");

Open API support

  • [ x] Option 1: Add Swagger UI to your application

Install the Microsoft Open API and Swagger packages.

Using .NET CLI

Microsoft open API

dotnet add package Swashbuckle.AspNetCore --version 6.1.4

In Visual Studio

In Visual Studio you can use the Package Manager Console or Manage Nuget Package GUI.

Install-Package Swashbuckle.AspNetCore -Version 6.1.4

Configure your the Swagger UI yourself

User configures Swagger UI on their own with the following snippets

Snippet 1: Below var builder = WebApplication.CreateBuilder(args);

add the following lines of code

builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new OpenApiInfo { Title = "Todo API", Description = "Keep track of your tasks", Version = "v1" });
});

Snippet 2: Above app.MapGet("/", () => "Hello World!");
add the following lines of code

app.UseSwagger();
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Todo API V1");
});
  • Option 2: Swagger Built into the template 😺

Alternative path: Swagger turned on my default

Example: user runs their app and navigates to this URL https://localhost:5001/docs/. No addtional code required.

docs-swagger

Working with data 😾

Working with In-memory database Microsoft.EntityFrameworkCore.InMemory
Implement - GET, POST, PUT, DELETE.

app.MapGet("/todo", () => new[] { new TodoItem { Id = 1, Item = "Water Plants", IsComplete = true } });

app.MapGet("/todos", async (TodoDb db) => await db.Todos.ToListAsync());

app.MapGet("/todos/{id}", async (TodoDb db, int id) => await db.Todos.FindAsync(id));

app.MapPost("/todos", async (TodoDb db,TodoItem todo) => 
{
    await db.Todos.AddAsync(todo);
    await db.SaveChangesAsync();
    return Created($"/todo/{todo.Id}", todo);
});


app.MapDelete("/todos/{id}", async ( TodoDb db, int id) =>
{
    var todo = await db.Todos.FindAsync(id);
    if (todo is null)
    {
        return NotFound();
    }
    db.Todos.Remove(todo);
    await db.SaveChangesAsync();

    return Ok();

});

image

Validation

details coming soon

Authorization

details coming soon

Deploy

details coming soon

Error messages

@LadyNaggaga LadyNaggaga self-assigned this Jul 1, 2021
@mkArtakMSFT mkArtakMSFT added area-runtime feature-minimal-actions Controller-like actions for endpoint routing labels Jul 1, 2021
@BrennanConroy BrennanConroy added this to the 6.0.0 milestone Jul 7, 2021
@DamianEdwards DamianEdwards added the User Story A single user-facing feature. Can be grouped under an epic. label Jul 15, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-minimal-actions Controller-like actions for endpoint routing User Story A single user-facing feature. Can be grouped under an epic.
Projects
None yet
Development

No branches or pull requests

5 participants