encode / django-rest-framework

Web APIs for Django. 🎸
https://www.django-rest-framework.org
Other
28.45k stars 6.84k forks source link

format_suffix_patterns applies them after trailing slash. #1516

Closed aop closed 9 years ago

aop commented 10 years ago

According to http://www.django-rest-framework.org/api-guide/format-suffixes the suffices should be used directly after the resource name like http://example.com/api/users.json but format_suffix_patterns applies them after the trailing slash if one is used in the urlpatterns it gets (like the DefaultRouter does)

This results in 404 when trying to use them in the tutorial app for example: http://restframework.herokuapp.com/users.json

tomchristie commented 10 years ago

Agree that that docs are misleading as to the current behavior there, but not sure if that's a docs fix, or if we need to change the default behavior.

tomchristie commented 10 years ago

Assuming this is a duplicate of #1319, but not clear to me that it really was properly addressed, or if #1333 (available in the upcoming 2.4.0) only addressed a subset of the problem.

tomchristie commented 10 years ago

DjangoCon sprint guidance - review current behaviour, summarise what you would expect desired behaviour to be.

kennyncsu commented 10 years ago

My expectations for the behavior would be the following:

# should work
example.com/test.json

# should NOT work
example.com/test/.json

I have mixed thoughts on the following: example.com/test.json/

I kind of like the idea of requiring the specification of a data format to be the very end of an address. This would mean not allowing a trailing slash. However, others may have use cases that would disagree with this approach.

Our group specifies content type via the HTTP Accept Header; however, I agree with the support for specifying the data format via an address.

Lastly, I think the documentation should at least be updated to include samples as to which addresses are expected to work based on the usage of the format_suffix_patterns functionality.

tomchristie commented 10 years ago

Seems reasonable.

jpadilla commented 10 years ago

I've always found that comments/.json is just plain weird and confusing.

Expected for me is:

http://localhost:8000/comments.json

# perhaps this too
http://localhost:8000/comments.json/
http://localhost:8000/comments/?format=json

If behavior doesn't change for now, updating docs might be a good idea.

mmarvick commented 9 years ago

I agree with this. This is coming from someone completely new to the framework and going through the tutorial, so take that as you wish. However, the tutorial even gives the example that using format_suffix_patterns should make it so the API will be able to handle URLs such as http://example.com/api/items/4.json

See here: http://www.django-rest-framework.org/tutorial/2-requests-and-responses/#adding-optional-format-suffixes-to-our-urls

Edit: The example HTTP requests later on the same page show the proper request with the trailing forward slash. So maybe this should just be a doc change higher up. However, I would still agree that without a forward slash makes more sense.