Changes

Jump to navigation Jump to search
8 bytes removed ,  13:42, 5 December 2018
This [[Module Library|XQuery Module]] contains a single function to send HTTP requests and handle HTTP responses. The function {{Code|send-request}} is based on the [http://expath.org/spec/http-client EXPath HTTP Client Module]. It gives full control over the available request and response parameters. For simple GET requests, the [[Fetch Module]] may be sufficient.
With {{Version|9.0}}, if If <code><http:header name="Accept-Encoding" value="gzip"/></code> is specified and if the addressed web server provides support for the {{Code|gzip}} compression algorithm, the response will automatically be decompressed.
=Conventions=
All functions in this module are assigned to the <code><nowiki>http://expath.org/ns/http-client</nowiki></code> namespace, which is statically bound to the {{Code|http}} prefix.<br/>
All errors are assigned to the <code><nowiki>http://expath.org/ns/error</nowiki></code> namespace, which is statically bound to the {{Code|exerrexperr}} prefix.
=Functions=
|-
| width='120' | '''Signatures'''
|{{Func|http:send-request|$request as element(http:request)?, $href as xs:string?, $bodies as item()*|item()+}}<br/>{{Func|http:send-request|$request as element(http:request)?, $href as xs:string?|item()+}}<br />{{Func|http:send-request|$request as element(http:request)?, $href as xs:string?, $bodies as item()*|item()+}}<br />
|-
| '''Summary'''
|Sends an HTTP request and interprets the corresponding response. :* {{Code|$request}} contains the parameters of the HTTP request such as HTTP method and headers. * In addition to this it can also contain the URI to which the request will be sent and the body of the HTTP method. * If the URI is not given with the parameter {{Code|$href}}, its value in {{Code|$request}} is used instead.<br/>* The structure request body can also be supplied via the {{Code|$bodies}} parameter. Notes:* Both basic and digest authentication is supported.* While the contents of the request can be supplied as child of the {{Code|http:requestbody}} element follows , it is faster and safer to pass them on via the third argument.* For further information, please check out the [http://expath.org/spec/http-client EXPath] specification. Both basic and digest authentication is supported.
|-
|'''Errors'''
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="contentContent-typeType" content="text/html; charset=ISO-8859UTF-18"/>
<title>Google</title>
<script>window.google={kEI:"rZB- ... </script> </center>
</body>
</html>
'''Query:'''
<pre class="brush:xquery">
let $http:send-request :=( <http:request href='http://localhost:8984/rest' method='post' username='admin' password='admin' send-authorization='true'> <http:body media-type='application/xml'/> <query xmlns="/http:request>, 'http://basex.orglocalhost:8984/rest"', <query> <text><![CDATA[ <html>{ for $i in 1 to 3 return <div>Section {$i }</div> }</html> ]]> </text> </query> </http:body> </http:request>return http:send-request($request)
</pre>
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu