Changeset 15115 in project for wiki/eggref/4/http-client


Ignore:
Timestamp:
06/30/09 00:00:46 (11 years ago)
Author:
sjamaan
Message:

Update docs to new API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/http-client

    r15029 r15115  
    3333easy to perform basic {{GET}} requests.
    3434
    35 <procedure>(call-with-response uri-or-request [writer] reader)</procedure>
     35<procedure>(call-with-response request writer reader)</procedure>
    3636
    3737This is the core http-client procedure.  It is only necessary to use
    3838this when you want the most control over the request/response cycle.
    39 {{uri-or-request}} is the request object, uri or string that contains
    40 information about the request to perform.  {{reader}} is a procedure
    41 that receives the response object and should read the request body,
    42 {{writer}} is an optional procedure that receives the request object
    43 and should write the request body.
     39{{request}} is the request object that contains information about the
     40request to perform.  {{reader}} is a procedure that receives the
     41response object and should read the request body, {{writer}} is a
     42procedure that receives the request object and should write the
     43request body.
    4444
    4545The {{writer}} should be prepared to be called several times; if the
     
    5454of redirects.
    5555
    56 <procedure>(call-with-input-request uri-or-request reader)</procedure>
     56<procedure>(call-with-input-request uri-or-request writer reader)</procedure>
    5757
    58 This procedure simply calls the {{reader}} with one argument: an input
    59 port from which the response body can be read.
     58This procedure is a convenience wrapper around {{call-with-response}}.
     59
     60It is much less strict - {{uri-or-request}} can be a request object, but
     61also an uri-common object or even a string with the URI in it, in which
     62case a request object will be automatically constructed around the URI,
     63using the {{GET}} method.
     64
     65{{writer}} can be either {{#f}} (in which case nothing is written), an
     66alist (in which case the data is written out as using
     67www-form-urlencoding, useful for POST requests), or a procedure that
     68accepts a port and writes the response data to it.
     69
     70{{reader}} is a procedure which accepts a port and reads out the data.
    6071
    6172Returns three values: The result of the call to {{reader}}, the
     
    6677includes {{404 not found}} (which is a {{client-error}}).
    6778
    68 <procedure>(with-input-request uri-or-request thunk)</procedure>
     79<procedure>(with-input-request uri-or-request write-thunk read-thunk)</procedure>
    6980
    70 Same as {{call-with-input-request}}, except this accepts a thunk
    71 (lambda of no arguments) which will be executed with
    72 {{current-input-port}} bound to the response port.
     81Same as {{call-with-input-request}}, except this accepts thunks
     82(lambdas of no arguments) which will be executed with the current
     83input (or output) port to the request or response port, respectively.
    7384
     85<examples>
    7486<example>
    7587<init>(use http-client)</init>
    76 <expr>(with-input-from-request "http://chicken.wiki.br/" read-string)</expr>
     88<expr>(with-input-from-request "http://chicken.wiki.br/" #f read-string)</expr>
    7789<result>"[the chicken wiki page HTML contents]"</result>
    7890</example>
     91<example>
     92<init>(use http-client uri-common intarweb)</init>
     93<expr>
     94;; Perform a POST of the key "test" with value "value" to an echo service
     95(with-input-from-request
     96  (make-request method: 'POST
     97                uri: (uri-reference "http://localhost/echo-service"))
     98  '((test . "value")) read-string)
     99</expr>
     100<result>"You posted: test=value"</result>
     101</example>
     102</examples>
     103
    79104
    80105==== Parameters
     
    119144{{VERSION}} is the version of this egg.
    120145
     146
    121147==== Connection management
    122148
     149<procedure>(close-connection! uri)</procedure>
     150
     151Close the connection to the server associated with the URI.
     152
     153<procedure>(close-all-connections!)</procedure>
     154
     155Close all connections to all servers.
     156
     157
     158==== Cookie management
     159
    123160TODO
     161
    124162
    125163=== Changelog
Note: See TracChangeset for help on using the changeset viewer.