Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b4e6f8d
Min Web API tutorial rewrite plus app samples updates v10
wadepickett Jun 25, 2026
b1cf8cb
Add Todo App update
wadepickett Jun 25, 2026
867750d
Update aspnetcore/tutorials/min-web-api.md
wadepickett Jun 26, 2026
955e38c
Update aspnetcore/tutorials/min-web-api.md
wadepickett Jun 26, 2026
265a702
Apply suggestions from code review
wadepickett Jun 26, 2026
e47562f
Update aspnetcore/tutorials/min-web-api.md
wadepickett Jun 26, 2026
6efa29f
Update aspnetcore/tutorials/min-web-api.md
wadepickett Jun 26, 2026
a5c7803
Updated to use Scalar
wadepickett Jun 28, 2026
9ff025e
Addressed review suggestions.
wadepickett Jun 28, 2026
0c6e468
Updating to new app samples now only one for VS and one for Scalar - …
wadepickett Jun 28, 2026
c6d9ea9
Updated app sample paths
wadepickett Jun 29, 2026
5b0d15f
sample path corection
wadepickett Jun 29, 2026
d377a43
vs samples path fix in tutorial
wadepickett Jun 29, 2026
5cbe05d
Adding more snippet tags for Typed version
wadepickett Jun 29, 2026
fb4f65e
Add snippet tags for Over-Posting example
wadepickett Jun 29, 2026
c6bef6b
Updated code snippet include formatting
wadepickett Jun 29, 2026
8d779b0
Additonal edits per style guide.
wadepickett Jun 29, 2026
9a013e6
fixed code link format
wadepickett Jun 29, 2026
3aeaf53
Removed AddDatabaseDeveloperPageExceptionFilter() since InMemory only…
wadepickett Jun 29, 2026
17f46b9
Replace missing AddOpenAPI line in code
wadepickett Jun 29, 2026
0440dd3
Removed text related to diagnostics
wadepickett Jun 29, 2026
b1a09d9
Put MapOpenAPI back in.
wadepickett Jun 29, 2026
ce97d77
Add new post ui image
wadepickett Jun 30, 2026
2b20a07
Add screenshot link
wadepickett Jun 30, 2026
e465cc8
Add screenshot link and stop instructions for patch secton
wadepickett Jun 30, 2026
619842c
Add stop and start instruction between sections
wadepickett Jul 1, 2026
903dfcb
Add generate request image
wadepickett Jul 1, 2026
333f2ff
General edits to follow style guide
wadepickett Jul 1, 2026
0c8de22
Add VSC start instruction
wadepickett Jul 1, 2026
376af4e
Added VSC launch config image
wadepickett Jul 1, 2026
e54391c
Fixed VSC tab block
wadepickett Jul 1, 2026
0ba0b44
Added scalar instruction line
wadepickett Jul 1, 2026
e6711d3
added more VSC start instruction
wadepickett Jul 1, 2026
be15ef8
Add more scalar instruction
wadepickett Jul 1, 2026
f6b846a
Added Patch instruction for resetting db with POST
wadepickett Jul 1, 2026
a45b334
Fixed VSC stop instructions
wadepickett Jul 1, 2026
6f923f2
One more edit sweep.
wadepickett Jul 1, 2026
b0b2283
Reword DI statment on code
wadepickett Jul 1, 2026
d812aa9
Fixed code highlight for DI.
wadepickett Jul 1, 2026
d5a958c
Apply suggestions from code review
wadepickett Jul 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 83 additions & 109 deletions aspnetcore/tutorials/min-web-api.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

app.UseHttpsRedirection();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");

app.Run();

internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
110 changes: 48 additions & 62 deletions aspnetcore/tutorials/min-web-api/samples/10.x/todo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
#define FINAL // MINIMAL FINAL WITHPATCH TYPEDR
#if MINIMAL
// <snippet_min>
#define WITHPATCH // TEMPLATESTART MINIMALSTART FINAL WITHPATCH TYPEDR
#if TEMPLATESTART
// <snippet_templatestart>
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

var app = builder.Build();

app.MapGet("/", () => "Hello World!");
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

app.UseHttpsRedirection();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");

app.Run();
// </snippet_min>

internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
// </snippet_templatestart>

#elif FINAL
// <snippet_all>

#elif MINIMALSTART
// <snippet_minimal_start_all>
using Microsoft.EntityFrameworkCore;

// <snippet_DI>
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<TodoDb>(opt => opt.UseInMemoryDatabase("TodoList"));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
var app = builder.Build();
// </snippet_DI>

Expand Down Expand Up @@ -76,13 +113,13 @@ is Todo todo
// </snippet_delete>

app.Run();
// </snippet_all>

// </snippet_minimal_start_all>
#elif WITHPATCH
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<TodoDb>(opt => opt.UseInMemoryDatabase("TodoList"));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
var app = builder.Build();

app.MapGet("/todoitems", async (TodoDb db) =>
Expand Down Expand Up @@ -148,58 +185,7 @@ is Todo todo
});

app.Run();
#elif TYPEDR
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<TodoDb>(opt => opt.UseInMemoryDatabase("TodoList"));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
var app = builder.Build();

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

app.MapGet("/todoitems/complete", async (TodoDb db) =>
await db.Todos.Where(t => t.IsComplete).ToListAsync());

// <snippet_1a>
app.MapGet("/todoitems/{id}", async (int id, TodoDb db) =>
await db.Todos.FindAsync(id)
is Todo todo
? Results.Ok(todo)
: Results.NotFound());
// </snippet_1a>

/*
// <snippet_1b>
app.MapGet("/todoitems/{id}", async Task<Results<Ok<Todo>, NotFound>> (int id, TodoDb db) =>
await db.Todos.FindAsync(id)
is Todo todo
? TypedResults.Ok(todo)
: TypedResults.NotFound());
// </snippet_1b>
*/

/*
// <snippet_111>
app.MapGet("/todoitems/{id}", async (int id, TodoDb db) =>
await db.Todos.FindAsync(id)
is Todo todo
? TypedResults.Ok(todo)
: TypedResults.NotFound());
// </snippet_111>
*/

// <snippet_11b>
app.MapGet("/hello", () => Results.Ok(new Message() { Text = "Hello World!" }))
.Produces<Message>();
// </snippet_11b>

// <snippet_112b>
app.MapGet("/hello2", () => TypedResults.Ok(new Message() { Text = "Hello World!" }));
// </snippet_112b>

app.Run();
#endif
#elif TYPEDR

#endif
2 changes: 1 addition & 1 deletion aspnetcore/tutorials/min-web-api/samples/10.x/todo/Todo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Todo
public class Todo
{
public int Id { get; set; }
public string? Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0.0-preview.5.24306.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0-preview.5.24306.3" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="10.0.9" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.9" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@TodoApi_HostAddress = http://localhost:5290

GET {{TodoApi_HostAddress}}/weatherforecast/
Accept: application/json

###
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

class TodoDb : DbContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class TodoPatchDto
public class TodoPatchDto
{
public string? Name { get; set; }
public bool? IsComplete { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading