2

I understand how to use Xpath

http://localhost:8080/exist/rest/db/movies?_query=//movie[title=%22Spider-Man%22]/node()

But how to pass an xquery query? I keep reading everywhere that the REST api is for both xpath and xquery but I can't get my query to work. Here is what I'm trying to pass as an example (I've tested this in the xquery sandbox and it works):

for $movie in doc("movies/movies.xml")/movies/movie[year > 2002]
    return <movie> { ($movie/title, $movie/year) } </movie>

How do I pass this in a URL? I dont really know where to start so I've tried just pasting the query above as the GET param, similar to the xpath query. So the url I pass is

http://localhost:8080/exist/rest/db/movies/?_query=for%20$movie%20in%20doc(%22movies/movies.xml%22)/movies/movie[year%20%3E%202002]%20return%20%3Cmovie%3E%20{%20($movie/title,%20$movie/year)%20}%20%3C/movie%3E

The page I get back is this page response

Am I going about this totally the wrong way? "movies" is a collection in my db. enter image description here

alex9311
  • 1,230
  • 1
  • 18
  • 42

1 Answers1

4

It looks like your query was successfully executed. The <exist:result/> element looks quite correct, but it simply didn't find any movies which fit your filter criteria. It might also be a namespace issue. You should try your query locally to see if it returns something.

Your <script id="tinyhippos-injected"/> element is rather weird, as I did not expect tiny hippos here. However, this seems to be due to some Chrome extension you use.

Also, if your XQuery is a bit longer a URL paramter will not do and the encoding is difficult to read and maintain anyways. You might want to take a look at the eXist documentation about how to submit a POST request with an XQuery.

dirkk
  • 6,160
  • 5
  • 33
  • 51
  • 2
    Another option is to parameterize your XQuery and store it into eXist, you can then call the XQuery via REST with your parameters. This is also covered in the eXist documentation. – adamretter May 19 '15 at 16:10