0

urls.py

url(r'^v1/files/$', MyFileView.as_view(), name='api-upload'),
url(r'^v1/files/$', MyFileView.as_view(), name='api-view-all'),

views.py

class MyFileView(APIView):
    def post():
        pass
    def get():
        pass

My question is: why POST api/v1/files works like GET api/v1/files/? I thought POST api/v1/files should return 404. Anything wrong?

UPDATE

But api/v1/files/<id> does not have this issue. api/v1/files/<id>/ will return 404. Thanks

BAE
  • 8,550
  • 22
  • 88
  • 171

1 Answers1

2

I think that they don't "work like GET".

What is really happening is that:

  • you send a POST url
  • the server replies with a HTTP 302 to url/
  • and the browser performs a GET url/.

And the result of that is what you actually see.

If you check the requests being actually sent along the wire, I suspect you'll see two requests - the first being the POST, the second being the GET.

LSerni
  • 55,617
  • 10
  • 65
  • 107
  • @Iserni, Intertesting. never known before. Thanks – BAE Nov 09 '16 at 22:02
  • Heh. Neither did I, I had to ask myself. You can't guess the head-scratching: http://stackoverflow.com/q/39848396/1428679 :-D – LSerni Nov 09 '16 at 22:06
  • But `api/v1/files/` does not have this issue. `api/v1/files//` will return 404. – BAE Nov 09 '16 at 22:20
  • Probably, under the hood, `files` is treated as a directory (and redirects), while `files/id` is treated as a file (and doesn't - nor can it get a further slash). It depends on how the routing is implemented server side. – LSerni Nov 09 '16 at 22:28