Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What encoding should I use for an HTTP PUT?

Tags:

rest

http

I am writing a webserver. I implemented GET and POST (application/x-www-form-urlencoded, multipart/form-data) and that works fine.

I am thinking of adding a RESTful module to the server. So had a look at some stuff that's out there and got opinions about when to PUT, POST, and GET.

My question is: what encoding (application/x-www-form-urlencoded, multipart/form-data) does PUT support (per the HTTP specifications), or can it handle both?

I am trying to make the webserver as standard specific as I can without shooting myself in the foot.

like image 585
Pintac Avatar asked May 24 '11 13:05

Pintac


People also ask

When should I use character encoding in HTTP headers?

Use character encoding declarations in HTTP headers if it makes sense, and if you are able, for any type of content, but in conjunction with an in-document declaration. Content authors should always ensure that HTTP declarations are consistent with the in-document declarations.

Which Unicode character encodings should be used for web content?

There are three different Unicode character encodings: UTF-8, UTF-16 and UTF-32. Of these three, only UTF-8 should be used for Web content. The HTML5 specification says "Authors are encouraged to use UTF-8.

When to use HTTP PUT and HTTP POST?

When to Use HTTP PUT and HTTP POST. The HTTP protocol defines two methods for updating a resource – PUT and POST. Both PUT and POST are used to modify a resource and this semantic similarity can confuse API developers. This confusion has led most developers to use POST for any action which may modify the state of a resource, ignoring PUT entirely.

What to look for when choosing an HTTP server-side encoding?

Check whether your choice will be affected by HTTP server-side settings. In addition to declaring the encoding of the document inside the document and/or on the server, you need to save the text in that encoding to apply it to your content. Developers also need to ensure that the various parts of the system can communicate with each other.


2 Answers

The limitation to application/x-www-form-urlencoded and multipart/form-data is not in the HTTP standard but in HTML. It's the only formats that can be created by an HTML form. From HTTP point of view, you can use any format, as long as you specify it to the server (Content-Type header) and obviously that the server can understand it. If not, it reply with a 415 Unsupported Media Type status code. See:

  • http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13.4
  • http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16
  • http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7
like image 78
Yannick Loiseau Avatar answered Oct 01 '22 08:10

Yannick Loiseau


HTTP PUT can have whatever content-type the user wishes (the same as for all other HTTP methods).

like image 26
Gili Avatar answered Oct 01 '22 09:10

Gili