Restxq
Saturday, 14 November 2015 · 5 messages · last reply 16 Nov 2015
M
meumapple14 Nov 2015 22:51 #
Hi All,
I am using restxq. I wrote a function which takes one variable (this should be a chunk of text, not a single word). The output is xml.
I can have the function work if I pass the content of the variable with
curl -X POST --data "variable=my text is long" http://addressHow can I get the same result of the curl command with an xquery function?
More in general, is this a good way to write a function in restxq when the variable is not a single word but the content of a file? (I am not even sure if a file can be passed as such in restxq)
Thanks,
Joseph
ML
Marco Lettere15 Nov 2015 10:19 #
Hi,
look at [1]. This is the documentation of the http client available in BaseX following eXpath specification in [2]. Your request in particularly should look like:
http:send-request(<http:request method="POST"/>, "http://address", "my text is long")or more declaratively:
http:send-request(
<http:request method="POST" href="http://address">
<http:body media-type="text/plain">My text is long</http:body>
</http:request>
)BR,
Marco.
[1] http://docs.basex.org/wiki/HTTP_Module#http:send-request [2] http://expath.org/spec/http-client
Quoted text · basex-talk-bounces at mailman.uni-konstanz.de · 12 lines
From: basex-talk-bounces at mailman.uni-konstanz.de <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of meumapple <meumapple at gmail.com> Sent: Saturday, November 14, 2015 10:51 PM To: BaseX Subject: [basex-talk] Restxq Hi All, I am using restxq. I wrote a function which takes one variable (this should be a chunk of text, not a single word). The output is xml. I can have the function work if I pass the content of the variable with curl -X POST --data "variable=my text is long" http://address How can I get the same result of the curl command with an xquery function? More in general, is this a good way to write a function in restxq when the variable is not a single word but the content of a file? (I am not even sure if a file can be passed as such in restxq) Thanks, Joseph
M
meumapple15 Nov 2015 11:51 #
Hi Marco,
Thanks. I knew that page but the function does not work. The variable is not passed, whether I write exactly what you write or I specify "text=my text is long" ("text" is the name of the variable in the restxq function).
Thanks,
J.
Quoted text · Marco Lettere · 1 line
Il giorno 15/nov/2015, alle ore 10:19, Marco Lettere <marco.lettere at dedalus.eu> ha scritto:
Hi,
look at [1]. This is the documentation of the http client available in BaseX following eXpath specification in [2]. Your request in particularly should look like:
http:send-request(<http:request method="POST"/>, "http://address", "my text is long")or more declaratively:
http:send-request(
<http:request method="POST" href="http://address">
<http:body media-type="text/plain">My text is long</http:body>
</http:request>
)BR,
Marco.
[1] http://docs.basex.org/wiki/HTTP_Module#http:send-request [2] http://expath.org/spec/http-client
Quoted text · basex-talk-bounces at mailman.uni-konstanz.de · 12 lines
From: basex-talk-bounces at mailman.uni-konstanz.de <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of meumapple <meumapple at gmail.com> Sent: Saturday, November 14, 2015 10:51 PM To: BaseX Subject: [basex-talk] Restxq Hi All, I am using restxq. I wrote a function which takes one variable (this should be a chunk of text, not a single word). The output is xml. I can have the function work if I pass the content of the variable with curl -X POST --data "variable=my text is long" http://address How can I get the same result of the curl command with an xquery function? More in general, is this a good way to write a function in restxq when the variable is not a single word but the content of a file? (I am not even sure if a file can be passed as such in restxq) Thanks, Joseph
ML
Marco Lettere15 Nov 2015 20:47 #
Hi,
mmhhh.. it's strange.
I tried the following which just replaces the href with one that makes sense on my PC:
http:send-request(
<http:request method="POST" href="http://localhost:8984/test">
<http:body media-type="text/plain">My text is long</http:body>
</http:request>
)and added this restxq to my server's restxq,xqm:
declare
%rest:path('test')
%rest:POST('{$body}')
%rest:consumes("text/plain")
function page:T($body as xs:string) {
<a>{$body}</a>
};
and when running the above request I get this response. Which looks correct.
<http:response xmlns:http="http://expath.org/ns/http-client" status="200" message="OK">
<http:header name="Content-Length" value="22"/>
<http:header name="Content-Type" value="application/xml; charset=UTF-8"/>
<http:header name="Server" value="Jetty(8.1.16.v20140903)"/>
<http:body media-type="application/xml"/>
</http:response>
<a>My text is long</a>Hope this helps you out.
Regards,
M.
Quoted text · meumapple at gmail.com · 36 lines
From: meumapple at gmail.com <meumapple at gmail.com> Sent: Sunday, November 15, 2015 11:51 AM To: Marco Lettere Cc: BaseX Subject: Re: [basex-talk] Restxq Hi Marco, Thanks. I knew that page but the function does not work. The variable is not passed, whether I write exactly what you write or I specify "text=my text is long" ("text" is the name of the variable in the restxq function). Thanks, J. Il giorno 15/nov/2015, alle ore 10:19, Marco Lettere <marco.lettere at dedalus.eu> ha scritto: Hi, look at [1]. This is the documentation of the http client available in BaseX following eXpath specification in [2]. Your request in particularly should look like: http:send-request(<http:request method="POST"/>, "http://address", "my text is long") or more declaratively: http:send-request( <http:request method="POST" href="http://address"> <http:body media-type="text/plain">My text is long</http:body> </http:request> ) BR, Marco. [1] http://docs.basex.org/wiki/HTTP_Module#http:send-request [2] http://expath.org/spec/http-client From: basex-talk-bounces at mailman.uni-konstanz.de <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of meumapple <meumapple at gmail.com> Sent: Saturday, November 14, 2015 10:51 PM To: BaseX Subject: [basex-talk] Restxq Hi All, I am using restxq. I wrote a function which takes one variable (this should be a chunk of text, not a single word). The output is xml. I can have the function work if I pass the content of the variable with curl -X POST --data "variable=my text is long" http://address How can I get the same result of the curl command with an xquery function? More in general, is this a good way to write a function in restxq when the variable is not a single word but the content of a file? (I am not even sure if a file can be passed as such in restxq) Thanks, Joseph
M
meumapple16 Nov 2015 19:09 #
Hi Marco,
Thanks! Yes now it works. The problem was that I did not use the variable in POST but in the form/query-param.
Thanks!
Joseph
Quoted text · Marco Lettere · 1 line
Il giorno 15/nov/2015, alle ore 20:47, Marco Lettere <marco.lettere at dedalus.eu> ha scritto:
Hi,
mmhhh.. it's strange.
I tried the following which just replaces the href with one that makes sense on my PC:
http:send-request(
<http:request method="POST" href="http://localhost:8984/test">
<http:body media-type="text/plain">My text is long</http:body>
</http:request>
)and added this restxq to my server's restxq,xqm:
declare
%rest:path('test')
%rest:POST('{$body}')
%rest:consumes("text/plain")
function page:T($body as xs:string) {
<a>{$body}</a>
};
and when running the above request I get this response. Which looks correct.
<http:response xmlns:http="http://expath.org/ns/http-client" status="200" message="OK">
<http:header name="Content-Length" value="22"/>
<http:header name="Content-Type" value="application/xml; charset=UTF-8"/>
<http:header name="Server" value="Jetty(8.1.16.v20140903)"/>
<http:body media-type="application/xml"/>
</http:response>
<a>My text is long</a>Hope this helps you out.
Regards,
M.
Quoted text · meumapple at gmail.com · 36 lines
From: meumapple at gmail.com <meumapple at gmail.com> Sent: Sunday, November 15, 2015 11:51 AM To: Marco Lettere Cc: BaseX Subject: Re: [basex-talk] Restxq Hi Marco, Thanks. I knew that page but the function does not work. The variable is not passed, whether I write exactly what you write or I specify "text=my text is long" ("text" is the name of the variable in the restxq function). Thanks, J. Il giorno 15/nov/2015, alle ore 10:19, Marco Lettere <marco.lettere at dedalus.eu> ha scritto: Hi, look at [1]. This is the documentation of the http client available in BaseX following eXpath specification in [2]. Your request in particularly should look like: http:send-request(<http:request method="POST"/>, "http://address", "my text is long") or more declaratively: http:send-request( <http:request method="POST" href="http://address"> <http:body media-type="text/plain">My text is long</http:body> </http:request> ) BR, Marco. [1] http://docs.basex.org/wiki/HTTP_Module#http:send-request [2] http://expath.org/spec/http-client From: basex-talk-bounces at mailman.uni-konstanz.de <basex-talk-bounces at mailman.uni-konstanz.de> on behalf of meumapple <meumapple at gmail.com> Sent: Saturday, November 14, 2015 10:51 PM To: BaseX Subject: [basex-talk] Restxq Hi All, I am using restxq. I wrote a function which takes one variable (this should be a chunk of text, not a single word). The output is xml. I can have the function work if I pass the content of the variable with curl -X POST --data "variable=my text is long" http://address How can I get the same result of the curl command with an xquery function? More in general, is this a good way to write a function in restxq when the variable is not a single word but the content of a file? (I am not even sure if a file can be passed as such in restxq) Thanks, Joseph
Written for BaseX 8.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery