Comments (3)
Hi @toraritte, thanks for creating this issue, I'll be taking a look at it this week.
from giraffe.
Hello again @toraritte. I've been looking for the official .NET documentation and other sources on the web, and I did test this option that you mentioned with the EndpointRoutingApp
sample from this repository. It didn't work for me. This was the code I was using, if you'd like to play with it (from samples/EndpointRoutingApp
):
open System
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Hosting
open Giraffe
open Giraffe.EndpointRouting
let handler1: HttpHandler =
fun (_: HttpFunc) (ctx: HttpContext) -> ctx.WriteTextAsync "Hello World"
let handler2 (firstName: string, age: int) : HttpHandler =
fun (_: HttpFunc) (ctx: HttpContext) ->
sprintf "Hello %s, you are %i years old." firstName age |> ctx.WriteTextAsync
let handler3 (a: string, b: string, c: string, d: int) : HttpHandler =
fun (_: HttpFunc) (ctx: HttpContext) -> sprintf "Hello %s %s %s %i" a b c d |> ctx.WriteTextAsync
let endpoints =
[ subRoute
"/foo"
[ GET
[ route "/bar" (text "aloha!")
route "/Bar" (text "Aloha!")
route "/BAR" (text "ALOHA!") ] ]
GET
[ route "/" (text "Hello World")
routef "/%s/%i" handler2
routef "/%s/%s/%s/%i" handler3 ]
GET_HEAD
[ route "/foo" (text "Bar")
route "/x" (text "y")
route "/abc" (text "def")
route "/123" (text "456") ]
// Not specifying a http verb means it will listen to all verbs
subRoute "/sub" [ route "/test" handler1 ] ]
let notFoundHandler = "Not Found" |> text |> RequestErrors.notFound
let configureApp (appBuilder: IApplicationBuilder) =
appBuilder.UseRouting().UseGiraffe(endpoints).UseGiraffe(notFoundHandler)
let configureServices (services: IServiceCollection) =
services.AddRouting(fun ctx -> ctx.LowercaseUrls <- false).AddGiraffe()
|> ignore
[<EntryPoint>]
let main args =
let builder = WebApplication.CreateBuilder(args)
configureServices builder.Services
let app = builder.Build()
if app.Environment.IsDevelopment() then
app.UseDeveloperExceptionPage() |> ignore
configureApp app
app.Run()
0
And was testing with:
curl localhost:5000/foo/bar
curl localhost:5000/foo/Bar
curl localhost:5000/foo/BAR
Any of these returned this exception:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HN2KSIQ7O89J", Request id "0HN2KSIQ7O89J:00000001": An unhandled exception was thrown by the application.
Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:
HTTP: GET /foo/bar
HTTP: GET /foo/Bar
HTTP: GET /foo/BAR
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(Span`1 candidateState)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, Span`1 candidateState)
at Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, Span`1 candidateState)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
from giraffe.
Thank you for taking the time looking into this and also for posting the sample code! I can't even name a valid use case for case-sensitive URL paths, but had to ask..:)
from giraffe.
Related Issues (20)
- LinkGenerator doesn't work with routef HOT 1
- Giraffe 6.2 is breaks against Microsoft.IO.RecyclableMemoryStream 3.0.0 HOT 11
- Returning streams, either with WriteStreamAsync or WriteFileStreamAsync or their handler equivalents, is extremely slow HOT 4
- Question: How to approach outside in testing of a micro service? HOT 2
- Guid pattern in endpoint router matches invalid values, throws System.FormatException HOT 6
- Follow-up from "Minor code optimisation #567"
- Update SECURITY.md
- Start using fantomas to validate code submissions with CI HOT 6
- [README] Suggestion for "Getting Started"'s "Doing it manually" HOT 2
- Remove NuGet API key from the repository HOT 3
- 6.4.0 release references PR for updating to .NET 7 instead of .NET 8 HOT 1
- EndpointRouting - Create endpoint for multiple http verbs
- Request/discussion: WriteStreamAsync buffer size autotuning and/or increase default buffer size HOT 1
- Update `.vscode` debug configuration to point to existent projects
- Returning 406 when mustAccept fails HOT 8
- Add documentation and sample for OpenApi configuration HOT 11
- F# compatible json serializer HOT 4
- Add mutation testing
- Looks like whole module `SystemTextJson` disappeared, but no mention in change log HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from giraffe.