Skip to content

Http method routing #87

@massover

Description

@massover

Code of Conduct

  • I agree to follow Django's Code of Conduct

Feature Description

Add http method routing to urlpatterns

Problem

This doesn't work right now because the first url pattern will always resolve.

urlpatterns = [
    path('pet', views.pet_list_view),
    path('pet', views.pet_create_view),
]

I understand that we can solve this built in right now by routing on class methods.

urlpatterns = [
    path('pet', views.PetView.as_view())
]

Also, it can be solved functionally by making our own "routing" view:

urlpatterns = [
    path('pet', list_router(get=views.pet_list_view, post=views.pet_create_view),
]

It also seems like it would be nice if this "just worked" (or some other chosen syntax):

urlpatterns = [
    path('pet', views.pet_list_view, methods=['GET'],),
    path('pet', views.pet_create_view, methods=['POST']),
]

Request or proposal

request

Additional Details

forum thread

I found some prior tickets/conversation, but nothing really seems to suggest there's a blocker:

https://code.djangoproject.com/ticket/33780

https://code.djangoproject.com/ticket/2784

https://groups.google.com/g/django-developers/c/FQVrKXkYAig

I think this would be a nice addition to django especially for building some simple json apis. Looking at the UrlResolver code, it seems like not the type of code to try and implement as a "django app". Thoughts?

Implementation Suggestions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Idea

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions