AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Route groups

Open Rick-Anderson opened this issue 1 year ago • 2 comments

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.

Rick-Anderson avatar Aug 25 '22 00:08 Rick-Anderson

@fiyazbinhasan once #26801 is approved, do you want to take the first check? Write the sample code?

Rick-Anderson avatar Aug 25 '22 01:08 Rick-Anderson

Sure. I would like to do that :)

fiyazbinhasan avatar Aug 25 '22 03:08 fiyazbinhasan

I think @tdykstra already started on this. Do let me know if you need a hand 😺

fiyazbinhasan avatar Sep 23 '22 06:09 fiyazbinhasan

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.

tdykstra avatar Sep 23 '22 16:09 tdykstra

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.

Rick-Anderson avatar Sep 23 '22 18:09 Rick-Anderson

@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

Rick-Anderson avatar Sep 23 '22 18:09 Rick-Anderson

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() and WithMetadata().

tdykstra avatar Sep 23 '22 20:09 tdykstra

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

Rick-Anderson avatar Sep 23 '22 21:09 Rick-Anderson

Since this is mainly to provide snippets for docs, wouldn't it fit better in the docs repo?

tdykstra avatar Sep 23 '22 22:09 tdykstra

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.

Rick-Anderson avatar Sep 23 '22 22:09 Rick-Anderson

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?

tdykstra avatar Sep 23 '22 23:09 tdykstra

Here's the format

:::code language="csharp" source="~/../AspNetCore.Docs.Samples/signalr/hubs/samples/6.x/SignalRHubsSample/Snippets/Hubs/ChatHub.cs" id="snippet_OnDisconnectedAsync":::

Rick-Anderson avatar Sep 23 '22 23:09 Rick-Anderson

Probably can live in this repo.

Rick-Anderson avatar Sep 23 '22 23:09 Rick-Anderson

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

Rick-Anderson avatar Sep 28 '22 01:09 Rick-Anderson

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.

tdykstra avatar Sep 29 '22 18:09 tdykstra

@fiyazbinhasan Do you still want to write this sample, and if so how soon could you have it ready?

tdykstra avatar Oct 03 '22 16:10 tdykstra

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

fiyazbinhasan avatar Oct 03 '22 17:10 fiyazbinhasan

@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

fiyazbinhasan avatar Oct 03 '22 17:10 fiyazbinhasan

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.

tdykstra avatar Oct 03 '22 17:10 tdykstra

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?

fiyazbinhasan avatar Oct 03 '22 17:10 fiyazbinhasan

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

tdykstra avatar Oct 03 '22 17:10 tdykstra

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

fiyazbinhasan avatar Oct 03 '22 18:10 fiyazbinhasan

That's two distinct MapTodos methods.

tdykstra avatar Oct 03 '22 18:10 tdykstra

ok, I'll upload something in a few hours. we will discuss afterwards

fiyazbinhasan avatar Oct 03 '22 18:10 fiyazbinhasan

@tdykstra I've scratched something out. should I push the sample in this repo or the other AspNetCore.Docs.Sample one?

fiyazbinhasan avatar Oct 03 '22 19:10 fiyazbinhasan

This repo https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/minimal-apis/7.0-samples/todo-group2

tdykstra avatar Oct 03 '22 19:10 tdykstra

Reopening, as only the code sample was done, still need to get route groups into a doc.

tdykstra avatar Oct 24 '22 23:10 tdykstra