This module provides an implementation of the
EXPath Http Client.
It provides functions for making HTTP requests and is a superset of the
module specified by EXPath.
Specifically, it implements the http:send-request()
functions
as specified by EXPath. Moreover, it adds an additional function
http:read()
(with several arities for the sake of ease).
In general, both functions take a description of the HTTP request to make as parameter, execute the request, and return a representation of the HTTP response. For instance, in the following code snippet, we fetch the Zorba home page:
import module namespace http = "http://expath.org/ns/http-client"; http:send-request( <http:request href="http://zorba.io" method="get" /> )
The http:send-request()
functions are declared as sequential.
Sequential functions are allowed to have side effects. For example, most probably,
an HTTP POST request is a request that has side effects because it adds/changes
a remote resource. Sequential functions are specified in the
XQuery Scripting Extension.
In contrast, the http:read() functions are not declared as sequential -
they are declared as nondeterministic though, which
means that several calls may return different results.
HTTP requests performed using these functions are not allowed to have
side effects.
The response is returned as a sequence of one or more items. The first
one is an http:response
element with quite the same
structure as an http:request, but without the content itself.
The content is returned as the second item (or several items in case of
a multipart response) as a string, a document node, or a binary item.
This depends on the content-type returned.
Specifically, the rules are as follows:
The structure of a request element is defined in the schema that is imported by this module. The details are described in the specification. Analogously, the response element is also described in this specification.
send-request
($request as element(*)) as item()+
Function for convenience. |
send-request
($request as element(*)?, $href as xs:string?) as item()+
Function for convenience. |
send-request
($request as element(*)?, $href as xs:string?, $bodies as item()*) as item()+
This function sends an HTTP request and returns the corresponding response. |
declare %an:sequential function http:send-request($request as element(*)) as item()+
http:send-request($request, (), ())
declare %an:sequential function http:send-request($request as element(*)?, $href as xs:string?) as item()+
http:send-request($request, $href, ())
declare %an:sequential function http:send-request($request as element(*)?, $href as xs:string?, $bodies as item()*) as item()+
This function is declared as sequential (see XQuery Scripting). Sequential functions are allowed to have side effects. For example, most probably, an HTTP POST request is a request that has side effects because it adds/changes a remote resource.