HTTP remote requests == Description == This page shows how to emit HTTP request from the HOP client side. These are used to address remote not HOP HTTP servers. == Synopsis == === Server === (with-url url success [fail]) (http-send-request request callback) == Examples == with-url, http-send-request == Server Definitions == === ++(with-url url success [:fail] [:header] [:timeout])++ === with-url ^ arguments ^ type ^ default ^ short description ^ | url | string | | a URL of a remote server. | | success | procedure | | a procedure of one argument. | | fail | procedure | ++raise++ | a procedure of one argument. | | header | list | ++()++ | an optional header list. | | timeout | integer | ++0++ | millisecond timeout. | The function ++with-url++ opens an HTTP connection with the remote server pointed to in the ++URL++. On success, it then invokes the function ++success++ with an object constructed from the service answer. On failure, it invokes ++failure++. ~~ The argument ++header++ can be used for sending extra information such as authentication to the remote host. It syntax is a list of pairs whose first element is a keyword and the second element a string of characters. ~~ If ++timeout++ is greater than ++0++, the connection will fail after the amount of time expressed in milliseconds has elapsed. ~~ The function ++with-url++ follows rules similar to the ++with-hop++ form interpreting the result of the HTTP transaction. It checks the status code of the HTTP response in order to build the value sent to ++success++: * 200 - the result is converted into a string. * 201 - the result is converted into a compound object using the JSON protocol (that is, using the ++json->obj++ function). * 202 - the result is converted into a compound object using ad-hoc unmarshalling technics. * 401, 407 - access denial. * all other status codes are interpreted as errors. === ++(http-send-request request callback)++ === http-send-request ^ arguments ^ type ^ short description ^ | request | ::http-request | a HTTP request. | | callback | procedure | a procedure of five arguments. | This low level function is used to handle primitive HTTP requests. It opens a connection to a remote HTTP server as referenced to by the ++request++. When such a connection is established, it calls the ++callback++ procedure with five parameters: - an input stream containing the characters of the response. If the response has no body, the input stream is the boolean ++#f++. - an integer denoting the status code. - an list denoting the whole HTTP response header. - an integer denoting the length of the body of the response. - the transfer encoding. == See also == with-url, http-send-request