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

Snippet to use with .Net Core 3.x using Endpoint routing #28

Open
guibirow opened this issue Jun 3, 2020 · 1 comment
Open

Snippet to use with .Net Core 3.x using Endpoint routing #28

guibirow opened this issue Jun 3, 2020 · 1 comment

Comments

@guibirow
Copy link

guibirow commented Jun 3, 2020

I ended here looking for same thing as many, given .Net Core 3+ now uses Endpoint routing, this library is not needed anymore.

To save you some time, the following code will give you similar results:


        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapGet("/routes", request =>
                {
                    request.Response.Headers.Add("content-type", "application/json");

                    var ep = endpoints.DataSources.First().Endpoints.Select(e => e as RouteEndpoint);
                    return request.Response.WriteAsync(
                        JsonSerializer.Serialize(
                            ep.Select(e => new
                            {
                                Method = ((HttpMethodMetadata)e.Metadata.First(m => m.GetType() == typeof(HttpMethodMetadata))).HttpMethods.First(),
                                Route = e.RoutePattern.RawText
                            })
                        )
                    );
                });
            });
        }

Just tweak with data you need from the routes.

@guibirow guibirow changed the title Snipped to use with .Net Core 3.x using Endpoint routing Snippet to use with .Net Core 3.x using Endpoint routing Jun 3, 2020
@richarddavenport
Copy link

@guibirow Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants