Hi, Gilles:

You could create a REST API resource service extension that supports the POST 
method, accepting a document with the XQuery code, evaluating the XQuery code, 
and returning an XML document.

Either the user will need the eval privilege or you'll need to add an amp to a 
role with the eval privilege. If you take the latter approach, you should 
install a library, amp the library, and call the library from the service. 

More information about resource services and libraries:

    http://docs.marklogic.com/REST/client/service-extension
    http://docs.marklogic.com/guide/rest-dev/extensions
    http://docs.marklogic.com/guide/rest-dev/extensions#id_55309

In MarkLogic 8, by the way, the REST API will support eval directly.


Hoping that helps,


Erik Hennum

________________________________________
From: [email protected] 
[[email protected]] on behalf of Gilles Lenfant 
[[email protected]]
Sent: Thursday, January 08, 2015 8:57 AM
To: [email protected]
Subject: [MarkLogic Dev General] XQuery results through REST

Hi,

I need to execute XQuery from a REST client app and retrieve results
as XML documents. I made a similar thing easily using exit-db back-end
but I'm somehow stuck to find the best practice with ML 7 to code the
same thing.

The pseudo-code (Python like) I made looks like this :

-----------
# Instanciate the client / server proxy
client = XQueryBackEnd(location_params, auth_token)

# Execute the query, and retrieve a results set reference
results_set = client.execute_xquery(some_xquery_script)

# Have error?
if results_set.error_message is not empty:
    exit()
end if

# How many results some_xquery_script yields
results_count = results_set.count

# Iterating through the XML results
for index in range(results_count):  # O, 1, ..., results_count - 1

    # Retrieve each individual result
    xml_result = results_set.get_item(index)

    # Make app stuffs with each individual result
    play_with(xml_result)

end for
----------

Any pointer that could help me to do the same thing the best way is
welcome. My only constraints are :

- I cannot use the Java API, only REST!

- I don't want to retrieve all results in the memory of the
results_set object since there may be thousands of big XML objects.

- The XQuery expressions are built/stored in the client app and NOT
pre-stored in the ML server.

Many thanks by advance
--
Gilles Lenfant
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to