WebStack

Annotated docs/methods.html

503:5e29854fe10d
2005-11-15 paulb [project @ 2005-11-15 15:46:01 by paulb] Added has_key method.
paulb@488 1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
paulb@488 2
<html xmlns="http://www.w3.org/1999/xhtml"><head>
paulb@488 3
  
paulb@488 4
  <title>Request Methods</title><meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" />
paulb@488 5
  <link href="styles.css" rel="stylesheet" type="text/css" /></head>
paulb@488 6
paulb@335 7
paulb@335 8
<body>
paulb@335 9
<h1>Request Methods</h1>
paulb@335 10
paulb@335 11
<p>In order for an application to behave in the right way when someone sends
paulb@335 12
a request into it, the application must take into consideration the type of
paulb@335 13
request being sent. The type of request is typically referred to as the
paulb@335 14
"request method" and indicates the kind of operation the user is attempting
paulb@335 15
to perform.</p>
paulb@335 16
paulb@335 17
<h2>Common Request Methods</h2>
paulb@335 18
paulb@335 19
<p>The following table summarises the most common methods defined for Web
paulb@488 20
applications in the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a> and <a href="http://www.faqs.org/rfcs/rfc2518.html">WebDAV</a> specifications:</p>
paulb@335 21
paulb@488 22
<table border="1" cellpadding="5" cellspacing="0">
paulb@335 23
  <tbody>
paulb@335 24
    <tr>
paulb@335 25
      <th>Method</th>
paulb@335 26
      <th>Type of Operation</th>
paulb@335 27
    </tr>
paulb@335 28
    <tr>
paulb@335 29
      <td>GET</td>
paulb@335 30
      <td>Retrieve a Web page or resource</td>
paulb@335 31
    </tr>
paulb@335 32
    <tr>
paulb@335 33
      <td>POST</td>
paulb@335 34
      <td>Present information to an application - for example, submission of
paulb@335 35
        fields in a form</td>
paulb@335 36
    </tr>
paulb@335 37
    <tr>
paulb@335 38
      <td>PUT</td>
paulb@335 39
      <td>Upload a new Web page or resource</td>
paulb@335 40
    </tr>
paulb@335 41
    <tr>
paulb@335 42
      <td>DELETE</td>
paulb@335 43
      <td>Delete a Web page or resource</td>
paulb@335 44
    </tr>
paulb@335 45
    <tr>
paulb@335 46
      <td>PROPFIND</td>
paulb@335 47
      <td>List resources on a server or in an application</td>
paulb@335 48
    </tr>
paulb@335 49
  </tbody>
paulb@335 50
</table>
paulb@335 51
paulb@335 52
<p>Most applications will at least need to support the GET request method in
paulb@335 53
order to support some kind of user experience, and those which employ forms
paulb@335 54
in Web pages will most probably want to support the POST request method,
paulb@335 55
too.</p>
paulb@335 56
paulb@335 57
<div class="WebStack">
paulb@335 58
<h3>WebStack API - Discovering the Request Method</h3>
paulb@335 59
paulb@335 60
<p>Transaction objects provide the following method for discovering the
paulb@335 61
request method:</p>
paulb@335 62
<dl>
paulb@335 63
  <dt><code>get_request_method</code></dt>
paulb@335 64
    <dd>This returns the request method being used in the request being
paulb@335 65
      handled.</dd>
paulb@335 66
</dl>
paulb@335 67
</div>
paulb@335 68
paulb@335 69
<h2>Rejecting Certain Request Methods</h2>
paulb@335 70
paulb@335 71
<p>Not all request methods are appropriate to every application. Should a
paulb@335 72
request be received which uses a method not supported by an application, the
paulb@335 73
most appropriate way of responding is to signal this condition to the sender
paulb@335 74
of the request. HTTP provides a response code to communicate just this kind
paulb@335 75
of condition - "405 Method Not Allowed".</p>
paulb@335 76
paulb@335 77
<div class="WebStack">
paulb@335 78
<h3>WebStack API - Signalling Unsupported Methods</h3>
paulb@335 79
paulb@335 80
<p>Transaction objects provide the <code>set_response_code</code> method (as
paulb@335 81
described in <a href="responses.html">"Responses and Presentation"</a>) to
paulb@335 82
communicate critical information on the success or failure of a request. In
paulb@335 83
this case, we would use this method on a transaction object
paulb@335 84
<code>trans</code> as follows:</p>
paulb@335 85
<pre>trans.set_response_code(405)</pre>
paulb@335 86
</div>
paulb@488 87
</body></html>