Giter Site home page Giter Site logo

Comments (9)

jchannon avatar jchannon commented on May 4, 2024

from carter.

loftum avatar loftum commented on May 4, 2024

Aha, I see.

I looked a little into it. I can see Carter uses IRouteBuilder.MapRoute(string template, RequestDelegate handler) to map routes:
https://github.com/CarterCommunity/Carter/blob/master/src/CarterExtensions.cs#L47

But there is also an extension for IRouteBuilder.MapVerb(string verb, string template, RequestDelegate handler)
(Microsoft.AspNetCore.Routing 2.1.1.0)

Would that do the trick?

from carter.

jchannon avatar jchannon commented on May 4, 2024

from carter.

jchannon avatar jchannon commented on May 4, 2024

Can you explain what happened when you switched the route order around?

from carter.

wastaz avatar wastaz commented on May 4, 2024

Ran into this issue again today, it seems a bit weird cause I would expect it to filter on verb first and on matching route after (or something similar). But if this is how aspnet core routing works then I understand if that is hard to change. Do you know if there is an issue for aspnetcore for this issue?

from carter.

jchannon avatar jchannon commented on May 4, 2024

I don't know if there is an issue, if you find one please link back

from carter.

wastaz avatar wastaz commented on May 4, 2024

I experimented today with just doing this instead (in pure aspnetcore without any carter or mvc)

            r.MapVerb("GET", "api/test/{id:long}/monkey", async (request, response, route) =>
            {
                await response.ReturnJsonWithStatusCode(HttpStatusCode.OK, new
                {
                    Id = long.Parse(route.Values["id"].ToString()),
                    Test = "Test1"
                });
            });
            
            r.MapVerb("PUT", "api/test/{id:long}/monkey", async (request, response, route) =>
            {
                await response.ReturnJsonWithStatusCode(HttpStatusCode.OK, new
                {
                    Id = long.Parse(route.Values["id"].ToString()),
                    Test = "Test2"
                });
            });

In plain aspnetcore it seems like this is matching the correct route. When I call this I get the expected things back depending on verb. Doing a similar thing with carter gives 405 method not allowed.

Am I missing something obvious or wouldnt this mean that switching to using MapVerb would solve this for carter?

from carter.

jchannon avatar jchannon commented on May 4, 2024

You need to create a verb with a catch all route?

r.MapVerb("GET","{type}", async....

from carter.

wastaz avatar wastaz commented on May 4, 2024

@jchannon Actually, disregard my latest comment. I did some more tests today and I realized that the problem that I am having is not he same problem as the original one in this issue (should have realized this sooner, sorry). I will create a new issue with a reproduction of that one instead of littering this issue with unrelated things.

from carter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.