Example of HTTP PUT method in HTML

I am trying to understand the use case of PUT method of HTTP. I have a basic apache web server running. I would see a working demo in HTML code which implement the PUT. Any help and info is very much appreciated. Thanks!
beer9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexandre SimõesManager / Technology SpecialistCommented:
PUT works like a POST that probably you know better.

PUT is one of the HTTP verbs that also contain GET, POST, PUT and DELETE.
There are others but these are the main 4.

Nothing actually forces their meaning but by convention, this is how they are meant to be used:
GET: Retrieve information
POST: Save a new piece of information
PUT: Update an existing piece of information
DELETE: Delete an existing piece of information

Here's the specification: RFC 2616

As I said, nothing forces these standards other than common sense and standards.
You can pretty much do everything with any of the verbs but if you're using or creating a REST API, the best practices say that to manipulate an entity, you should use the same URL and only change the verb and the information passed.
Dave BaldwinFixer of ProblemsCommented:
GET is the only one that works by itself.  POST, PUT, and DELETE require a program on the server to finish those operations.  They often require a login also so unwanted people can't change the files on your server.
Alexandre SimõesManager / Technology SpecialistCommented:
I just felt like I needed to comment your post @Dave, just to avoid confusion.

GET is the only one that works by itself.  POST, PUT, and DELETE require a program on the server to finish those operations.
This is true up to a certain point. Sure HTTP GET requests are the ones used to load files on the server, but if you use GET to load a business object value you still need a server-side piece of code to process it.
(POST, PUT and DELETE)... They often require a login also...
HTTP verbs don't require anything. It's your application logic that determines which requests need to be secured and which do not.
Securing GET requests is as important as securing any other verbs, depending exclusively on your application logic.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dave BaldwinFixer of ProblemsCommented:
You're being picky in a way that doesn't help the question.  GET will load an HTML file that doesn't have any other requirements.  While technically a POST will cause a page to be loaded, nothing is done with the POST data unless the page has some kind of programming to receive the POST data.  A simple HTML page will not do anything with the POST data.  There is little point in trying to use the 'verbs' if nothing is being done with them.

Now if you have the demo files to show how to use a PUT verb, please post them.  I would certainly try them on the servers I have.
Alexandre SimõesManager / Technology SpecialistCommented:
I'm just trying to teach what these protocol verbs are and how they should be used.

From the original question we can read:
I would see a working demo in HTML code which implement the PUT...
There's no implementation of PUT in HTML.
According to HTML Standards the only allowed verbs in a <form> are GET and POST. You can refer to the HTML Standards point 17.3
I also went to check the HTML Standards and I see no mention to other than GET and POST.

All this means that to use these other verbs we're no longer bound to the HTML specs but to the HTTP specs. If we're dealing with HTTP we're speaking about AJAX call for instance.
An example of this would be an ajax call meant to update some data on the server.

Here's a simple example where HTTP verbs are useful.
Notice that the url is always the same and identifies the entity you want to manipulate.
What defines the action you want to perform is the HTTP verb (that's why it's called a verb).
// get the person which id is 10
$.ajax({
    url: '/api/person',
    type: 'GET',
    data: { id: 10 }
});

// save a new person
$.ajax({
    url: '/api/person',
    type: 'POST',
    data: { name: 'Alex', gender: 'male' }
});

// update the name of a person which id is 10
$.ajax({
    url: '/api/person',
    type: 'PUT',
    data: { id: 10, name: 'Alexandre' }
});

// delete a person which id is 10
$.ajax({
    url: '/api/person',
    type: 'DELETE',
    data: { id: 10 }
});

Open in new window

Dave BaldwinFixer of ProblemsCommented:
That's nice but it's only the client half of a working example.  Here's a PHP example of using PUT: http://php.net/manual/en/features.file-upload.put-method.php .  Note that it says you have to tell Apache what program is going to handle PUT requests.

And here is some info about PUT and DELETE on IIS7.
http://forums.iis.net/t/1166025.aspx?How+to+enable+PUT+and+DELETE+verbs+on+IIS+7
Alexandre SimõesManager / Technology SpecialistCommented:
On the server you can use whatever technology can receive an HTTP request.
As long as you already have an application listening on a web server, that application will be able to process any HTTP verb.

For .Net, WCF, WebAPI or a Generic Handler are the most common options.
Also in the ASP.net MVC ecosystem you can simply point to controllers and get all the dispatching done through the routing and methods decoration.

For JAVA, Spring or any other MVC framework will work the same way as described above for ASP.net MVC.
For a pure REST implementation I also used RestEasy

For PHP I never used but I know that there are quite a few REST API tools available like Slim Framework

Cheers!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John KawakamiCommented:
PUT is used with REST APIs, and is generally requested from a program, typically a Javascript program.

It's like the opposite of GET, because it's supposed to replace an object on the server with new data, but its technical operation is more like POST.

POST is a kind of catch-all verb, which can operate like PUT, GET, or DELETE.  It's best use, however, is to add a document to a collection of documents.  The best analogy I've read is that it's like posting a message on a board. You "post", and it adds a new message to a list of similar messages.

PUT, in contrast, would be like replacing a message with a different or updated message.

Let's suppose you have a collection of messages at a URL: http://example.com/board/1/messages/

Imagine that, at that URL, there are a list of messages.

When you want to post a message, you use a form, and use the POST method to add it to that URL.

Now, suppose there's a way to display a single message. Some sites have a think called a "permalink", which is the URL to a message.  Here's an example: http://example.com/board/1/messages/543

That's message #543.  Well, if the server supported PUT, a Javascript program could tell it "PUT this data to http://example.com/board/1/messages/543.  That would update the message.

Using PUT is an unusual thing. HTML supports only GET and POST requests - it's part of the HTML specification.  To do a PUT you need a program to generate a PUT request. So, that's why they use Javascript.

Additionally, the server-side software generally uses POST to do everything.  That's how it's been done for a couple decades, and old habits die hard.  The new frameworks support PUT, but it'll take a while for it to catch on, because,  in javascript, performing a POST is not any harder than performing a PUT.  Because HTML supports POST, you can test out POSTs by making an HTML form and submitting it via the browser; you can't test PUTs as easily.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.