Changes

Jump to navigation Jump to search
1,030 bytes added ,  15:42, 18 July 2023
no edit summary
* {{Code|$request}} contains an {{Code|<http:request/>}} element with a {{Code|method}} attribute, an {{Code|href}} attribute with the target URI, and optional header and body elements.
* The request is either sent to the URI of the {{Code|$href}} argument or (if empty) to the URI supplied via the {{Code|href}} attribute.
* In addition to the attributes of the official specification, {{Code|csv}}, {{Code|json}}, {{Code|html}} and {{Code|text}} attributes can be supplied to define how to convert the response body(see [[#Response Conversion|Response Conversion]] for an example).
Notes:
==Status Only==
 
Simple GET request. As the attribute {{Code|status-only}} is set to true, only the response element is returned.
};
</syntaxhighlight>
 
==Response Conversion==
 
Converts the response body to a specific JSON format:
 
'''Query:'''
 
<syntaxhighlight lang="xquery">
http:send-request(<http:request method='GET' href='http://localhost:8080/json' json='format=xquery'/>)
</syntaxhighlight>
 
'''Result:'''
<syntaxhighlight lang="javascript">
map { "abcde": 12345 }
</syntaxhighlight>
 
Without the {{Code|csv}} attribute, the response body is converted to the default XML representation:
 
<syntaxhighlight lang="xml">
<json type="object">
<abcde>12345</abcde>
</json>
</syntaxhighlight>
 
'''RESTXQ service:'''
 
<syntaxhighlight lang="xquery">
declare
%rest:path('json')
%output:method('json')
function local:json() {
map { 'abcde': 12345 }
};
</syntaxhighlight>
 
See the [[CSV Module]], [[JSON Module]] and [[HTML Module]] for a list of the available options.
=Errors=
=Changelog=
 
;Version 11.0
* Updated: {{Function||http:send-request}}: {{Code|csv}}, {{Code|json}}, {{Code|html}} and {{Code|text}} attributes added.
;Version 10.0
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu