django-rest-framework/docs/topics/browserhacks.md
2012-10-08 12:17:43 +01:00

1.7 KiB

Browser hacks

"There are two noncontroversial uses for overloaded POST. The first is to simulate HTTP's uniform interface for clients like web browsers that don't support PUT or DELETE"

RESTful Web Services, Leonard Richardson & Sam Ruby.

Browser based PUT, DELETE, etc...

TODO: Preamble. Note that this is the same strategy as is used in Ruby on Rails.

For example, given the following form:

<form action="/news-items/5" method="POST">
    <input type="hidden" name="_method" value="DELETE">
</form>

request.method would return "DELETE".

Browser based submission of non-form content

Browser-based submission of content types other than form are supported by using form fields named _content and _content_type:

For example, given the following form:

<form action="/news-items/5" method="PUT">
    <input type="hidden" name="_content_type" value="application/json">
	<input name="_content" value="{'count': 1}">
</form>

request.content_type would return "application/json", and request.content would return "{'count': 1}"

URL based accept headers

URL based format suffixes

Doesn't HTML5 support PUT and DELETE forms?

Nope. It was at one point intended to support PUT and DELETE forms, but was later dropped from the spec. There remains ongoing discussion about adding support for PUT and DELETE, as well as how to support content types other than form-encoded data.