AspNetCore.Docs
AspNetCore.Docs copied to clipboard
Route groups
Probably do this in multiple PR's
- [x] sample code #27034
- [ ] New 7.0 sample code in https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/tutorials/min-web-api/samples/7.x and #26818
- [ ] Update this doc using code from previous bullet. Use absolute links for snippets so they can be copied/pasted in any document.
- [ ] Update Minimal APIs overview and What's new in ASP.NET Core 7.0
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: ab408035-6313-a183-9940-32de00e0e977
- Version Independent ID: ab408035-6313-a183-9940-32de00e0e977
- Content: Tutorial: Create a minimal web API with ASP.NET Core
- Content Source: aspnetcore/tutorials/min-web-api.md
- Product: aspnet-core
- Technology: aspnetcore-tutorials
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
@fiyazbinhasan once #26801 is approved, do you want to take the first check? Write the sample code?
Sure. I would like to do that :)
I think @tdykstra already started on this. Do let me know if you need a hand 😺
Yes I do! The MapGroup sample code I have in the intro tutorial is too basic for the what's new article. For the what's new I need an example that includes code similar to what we have in the Preview 4 blog post, i.e., code that illustrates what you can do with route groups in more advanced scenarios. This sample would ideally also include code that returns multiple result types from an endpoint.
For the what's new I need an example that includes code similar to what we have in the Preview 4 blog post, i.e., code that illustrates what you can do with route groups in more advanced scenarios. This sample would ideally also include code that returns multiple result types from an endpoint.
Make sure that code makes it into a primary article, either Minimal APIs overview or better yet a new article under that.
What's new is the short version of what goes into primary articles with a link to the primary. When a new programmer starts .NET 9, she doesn't need to go to WN in .NET 7 to find features.
@tdykstra @fiyazbinhasan and the sample should go in https://github.com/dotnet/AspNetCore.Docs.Samples
@tdykstra how much more do you need than what's in https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/MinApiTestsSample
how much more do you need
It's not ideal for showing what you can do with routes. The middleware code gets in the way of showing the MapVerb method calls, and the code doesn't illustrate this statement, which the blog code does:
It allows for customizing entire groups of endpoints with a single call to methods like
RequireAuthorization()
andWithMetadata()
.
What I should have said is create an issue in https://github.com/dotnet/AspNetCore.Docs.Samples/issues and list what you need with the though that it could borrow much from the tests sample
Since this is mainly to provide snippets for docs, wouldn't it fit better in the docs repo?
Since this is mainly to provide snippets for docs, wouldn't it fit better in the docs repo?
If we expect customers to download the code, then it should go in the samples repo. If it's a good sample to download, the samples repo.
I don't think this needs to be a download-friendly sample--do you think otherwise? If so, can you point me to a doc that displays snippets from code in the samples repo?
Here's the format
:::code language="csharp" source="~/../AspNetCore.Docs.Samples/signalr/hubs/samples/6.x/SignalRHubsSample/Snippets/Hubs/ChatHub.cs" id="snippet_OnDisconnectedAsync":::
Probably can live in this repo.
I don't think this needs to be a download-friendly sample--do you think otherwise? If so, can you point me to a doc that displays snippets from code in the samples repo?
For route groups we have the sample code at https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/7.0-samples/todo-group
I need a project that I can use for snippets in the overview article sections on MapGroup and returning multiple result types. The snippets need to show what the Preview 4 blog shows:
- Map the same collection of endpoints using two different groups configured differently (in the blog code, one requires authz, one does not)
- The collection of endpoints is a series of MapGet, MapPost ,etc. statements without extraneous code such as for endpoint filters, i.e., a short method like what is shown as the MapTodosApi method in the Preview 4 blog
- Endpoint handler code for POST uses relative path to support multiple group prefixes, like the CreateTodo method in the Preview 4 blog.
- In the handler methods use TypedResults
The project can be put in https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/7.0-samples/todo-group2 to differentiate it from the existing ...todo-group sample.
@fiyazbinhasan Do you still want to write this sample, and if so how soon could you have it ready?
Do you need something more than this one? I've two endpoint group here that covers everything. https://github.com/dotnet/AspNetCore.Docs.Samples/tree/main/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup
@tdykstra plz check these groups https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/TodoEndpointsV1.cs and https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/TodoEndpointsV2.cs
Those don't provide what I need for snippets, as described in https://github.com/dotnet/AspNetCore.Docs/issues/26819#issuecomment-1262684941 e.g. they have extraneous endpoint filter code.
ok. I'll bootstrap a separate project and upload it to this repo. but it would be pretty much same without filters. TodoEndpointV1 and TodoEndpointV2. Are you ok with that?
See the Preview 4 blog section on route groups and the way it calls the same MapGet etc. endpoint code for setting up each group
Isn't this the same thing?
// todoV1 endpoints app.MapGroup("/todos/v1") .MapTodosApiV1() .WithTags("Todo Endpoints");
// todoV2 endpoints app.MapGroup("/todos/v2") .MapTodosApiV2() .WithTags("Todo Endpoints");
https://github.com/dotnet/AspNetCore.Docs.Samples/blob/main/fundamentals/minimal-apis/samples/MinApiTestsSample/WebMinRouteGroup/Program.cs#L24-L32
That's two distinct MapTodos methods.
ok, I'll upload something in a few hours. we will discuss afterwards
@tdykstra I've scratched something out. should I push the sample in this repo or the other AspNetCore.Docs.Sample
one?
This repo https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/7.0-samples/todo-group2
Reopening, as only the code sample was done, still need to get route groups into a doc.