restxq - adam retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · restxq •...
TRANSCRIPT
![Page 1: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/1.jpg)
Adam Retter
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
RESTXQXQuery 3.0
Annotations for REST
@ MarkLogic User Group London8th March 2012
![Page 2: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/2.jpg)
Adam Retter
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
Freelance Consultant
…Not a MarkLogic Employee or User!
eXist-dbW3C XQuery WG EXQuery
XML Guild Member
Software Engineer
eXist Solutions
Almost worked forMarkLogic!
XQuery WebAppEvangelist
![Page 3: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/3.jpg)
RESTXQ
1. The Problem!
2. The Solution?
3. Proof of Concept
4. How to Implement
5. Now and Then
Agenda
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
A revision of my XML Prague 2012 presentationwith ++
![Page 4: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/4.jpg)
RESTXQ
…or, how I ended up here,
and why I care.
The Problem!
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 5: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/5.jpg)
RESTXQ
• Building Web Applications in XML tech.
• Why?– Good at producing (X)HTML, CSS, JSON, etc.
– Data access is implicit (XPath, doc(), etc)
– Same Type-Model for data and implementation
Makes development, easy and fast.
What am I trying to achieve?
XQuery 3.0 Annotations for REST
The Problem!
#adamretter http://www.adamretter.org.uk [email protected]
![Page 6: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/6.jpg)
RESTXQ
XPath, XQuery, XSLT and XProc all lack:
• Standard Web Connectivity– How to associate a URI with…
• Standard Web Context operations– Cannot process HTTP Request
– Cannot create HTTP Response
• Vendors!!!
No Standard Web Capability
XQuery 3.0 Annotations for REST
The Problem!
#adamretter http://www.adamretter.org.uk [email protected]
![Page 7: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/7.jpg)
RESTXQ
• Implement W3C Standards
• Create/meet demand by adding value….
– Innovate
• Implementation features
• Language Extensions…
XQuery 3.0 Annotations for REST
The Problem!Vendors Compete
#adamretter http://www.adamretter.org.uk [email protected]
![Page 8: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/8.jpg)
RESTXQ
• Extensions for accessing the Web Context– Extension functions e.g. Get HTTP Request
Parameter
• Implementation for Web Connectivity– Invoking XML processing with a HTTP Request
• Extensions are non-standard– Code becomes Non-Portable– Vendor Lock-In– Contribution back into Standards?
XQuery 3.0 Annotations for REST
The Problem!Vendors Innovate
#adamretter http://www.adamretter.org.uk [email protected]
![Page 9: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/9.jpg)
RESTXQ
• Herein we solely focus on XQuery
• Lessons and Proposals could equally be applied to XSLT, XProc and others.
The Problem!XQuery*
(*not the problem itself!)
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 10: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/10.jpg)
RESTXQ
…or, XQuery Web App Examples
The Wheel Factory
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 11: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/11.jpg)
RESTXQ
• Create a new Wheel
• Store a Wheel in the Warehouse
• Inventory of Wheels in the Warehouse
• Retrieve a Wheel from the Warehouse
The Problem!The Wheel Factory:
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 12: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/12.jpg)
wheel.xqm (1/2)
![Page 13: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/13.jpg)
wheel.xqm (2/2)
![Page 14: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/14.jpg)
RESTXQ
• Assuming:– We want REST Services
– We want logical URIs
• Require vendor processor support for Web Context
• Require function extensions for XQuery
The Problem!The Wheel Factory as a Service
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 15: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/15.jpg)
RESTXQ
• Create a new WheelPOST /factory/warehouse/wheel
• Store a Wheel in the WarehousePUT /factory/warehouse/wheel/some-id
• Inventory of Wheels in the WarehouseGET /factory/warehouse/wheel
• Retrieve a Wheel from the WarehouseGET /factory/warehouse/wheel/some-id
The Problem!RESTful HTTP Wheel Factory:
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 16: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/16.jpg)
The Wheel Factory Service
implemented in
eXist-db URL Rewrite
![Page 17: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/17.jpg)
controller.xql (1/2)
![Page 18: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/18.jpg)
controller.xql (2/2)
![Page 19: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/19.jpg)
The Wheel Factory Service
implemented in
MarkLogic REST Library
![Page 20: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/20.jpg)
rewriter.xqy
![Page 21: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/21.jpg)
endpoints.xqm (1/2)
![Page 22: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/22.jpg)
endpoints.xqm (2/2)
![Page 23: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/23.jpg)
wheel-proxy.xqm
![Page 24: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/24.jpg)
XQuery Web Apps are beautiful…but each uses different shaped wheels
Flickr CC-BY: a bike that can only run on special roads by vrogy
![Page 25: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/25.jpg)
RESTXQ
• Why no W3C Standards?
– XQuery/XSLT/XProc was not envisaged for this task
– Out-of-Scope? Good -> focus on Core enablers
– Must see requirement and support…
• Standard Proposal
– Initial impetus, individual/organisation research
– Peer Review and grow in the community
• EXQuery/EXPath/W3C Community Group
The Problem!There is no Standard
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 26: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/26.jpg)
RESTXQ
…or, an approach that I came up with.
The Solution?
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 27: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/27.jpg)
RESTXQ
Build Web Applications in XML technologies:
• Portable Code
• Vendor Agnostic– Implementer Friendly
• Simple for XQuery Developers
• Easily Web-enable existing code
• Win!XQuery 3.0 Annotations for REST
The Solution?Goals
#adamretter http://www.adamretter.org.uk [email protected]
![Page 28: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/28.jpg)
![Page 29: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/29.jpg)
RESTXQ
• XQuery 3.0 adds Annotations– Specifies %public and %private
“Implementations MAY define further annotations, whose behaviour is implementation-defined”
• JSR-311: Java Annotations for REST– We apply these ideas to XQuery 3.0
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
#adamretter http://www.adamretter.org.uk [email protected]
![Page 30: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/30.jpg)
RESTXQ
• Functions => Resource Functions– Constraint Annotations
– Parameter Annotations
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
#adamretter http://www.adamretter.org.uk [email protected]
![Page 31: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/31.jpg)
RESTXQ
Path Annotation (Constraint)– Matching
– Templating
– Auto-Type Conversion (xs:anyAtomicType)
%rest:path(“/product/{$prod-id}/part/{$part-id}”)
my:part-lookup($prod-id as xs:string, $part-id as xs:integer, $sid)
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
?
#adamretter http://www.adamretter.org.uk [email protected]
![Page 32: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/32.jpg)
RESTXQ
HTTP Method Annotation (Constraint)– Resource Function may have more than one
– Simple Method Annotations%rest:GET
%rest:HEAD
%rest:DELETE
– Content Method Annotations (optional body)%rest:POST %rest:POST(“{$body}”)
%rest:PUT %rest:PUT(“{$body}”)
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
#adamretter http://www.adamretter.org.uk [email protected]
![Page 33: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/33.jpg)
RESTXQ
Media Type Annotations (Constraint)
– HTTP Content Type
• One or more Internet Media Types
%rest:consumes(“text/xml”, “application/xml”)
– HTTP Accept
%rest:produces(“application/atom+xml”)
– Constraint, so if omitted, then default is */*
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
#adamretter http://www.adamretter.org.uk [email protected]
![Page 34: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/34.jpg)
RESTXQ
Query String Annotations (Parameter)%rest:query-param(“my-field”, “{$my-param}”)
– Optional default value
%rest:query-param(“my-field”, “{$my-param}”, “default value”)
%rest:query-param(“my-field”, “{$my-param}”, 1234)
– Parameter, so if omitted, then default value or ignore
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
#adamretter http://www.adamretter.org.uk [email protected]
Auto-Type Conversion!
![Page 35: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/35.jpg)
RESTXQ
HTML Form field Annotations (Parameter)%rest:form-param(“my-field”, “{$my-param}”)
– Optional default value
%rest:form-param(“my-field”, “{$my-param}”, “default value”)
%rest:form-param(“my-field”, “{$my-param}”, 1234)
– Seamlessly extracted from POST or GET
– Parameter, so if omitted, then default value or ignore
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
#adamretter http://www.adamretter.org.uk [email protected]
Auto-Type Conversion!
![Page 36: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/36.jpg)
RESTXQ
HTTP Header Annotations (Parameter)%rest:header-param(“my-header”, “{$my-hdr}”)
– Optional default value%rest:header-param(“my-header”, “{$my-hdr}”, “default”)
%rest:header-param(“my-header”, “{$my-hdr}”, 1234)
– Parameter, so if omitted, then default value or ignore
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
#adamretter http://www.adamretter.org.uk [email protected]
Auto-Type Conversion!
![Page 37: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/37.jpg)
RESTXQ
Cookie Annotations (Parameter)%rest:cookie-param(“my-cookie”, “{$my-ckie}”)
– Optional default value%rest:header-param(“my-cookie”, “{$my-ckie}”, “default”)
%rest:header-param(“my-cookie”, “{$my-ckie}”, 1234)
– Parameter, so if omitted, then default value or ignore
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
#adamretter http://www.adamretter.org.uk [email protected]
Auto-Type Conversion!
![Page 38: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/38.jpg)
RESTXQ
Serialization; Resource Function returns either:
1. ResourceThe result of the XQuery function
2. rest:response element Serialization settings, HTTP Headers, Status Code and Reason
3. rest:response and Resource(<rest:response >…</rest:response>, $resource)
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
![Page 39: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/39.jpg)
RESTXQ
Controlling Serialization:
1. Annotations based on W3C XSLT and XQuery Serialization 3.0%output:method(“xhtml”) static!
2. W3C XSLT and XQuery Serialization 3.0 Serialization Parameters in rest:response
<rest:response><output:serialization-parameters>
<output:method value=“html”/></output:serialization-parameters>…
</rest:response> dynamic, can override annotation in (1)!
XQuery 3.0 Annotations for REST
The Solution?RESTful Annotations
![Page 40: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/40.jpg)
RESTXQ
…demo of an implementation
Proof of Concept
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 41: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/41.jpg)
The Wheel Factory Service
Re-inventing
RESTful Annotations
![Page 42: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/42.jpg)
RESTfulwheel.xqm (1/2)
![Page 43: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/43.jpg)
RESTfulwheel.xqm (2/2)
![Page 44: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/44.jpg)
RESTXQ
• Portable Code– No longer needs vendor extensions!– No RESTful Annotation support? Code is still valid!
• Vendor Agnostic– RESTful Annotations can be implemented by any and all
• Simple for XQuery Developers– Declarative annotations sit beside your functions– Mappings are obvious
• Easily Web-enable existing code– RESTful Annotations can be added to existing functions
XQuery 3.0 Annotations for REST
Proof of ConceptSatisfies our Goals:
#adamretter http://www.adamretter.org.uk [email protected]
![Page 45: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/45.jpg)
RESTXQ
…for vendors
How to Implement
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 46: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/46.jpg)
RESTXQ
Requires Pre-Knowledge of Annotations
• Adapt XQuery Grammar– Its not part of the W3C XQuery spec (yet)– Adapting Grammars and Parsers is hard!
• Compilation Hook– Compile XQuery on Save/Store, Extract anns. from AST– Can still throw Static Analysis Errors– W3C XQuery and other Annotations can evolve
independently
• Translate XQuery to Vendor Specific XQueryXQuery 3.0 Annotations for REST
How to ImplementImplementation Options:
#adamretter http://www.adamretter.org.uk [email protected]
![Page 47: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/47.jpg)
RESTXQ
XQuery 3.0 Annotations for REST
How to ImplementCompilation Hook in eXist-db:
#adamretter http://www.adamretter.org.uk [email protected]
![Page 48: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/48.jpg)
RESTXQ
XQuery 3.0 Annotations for REST
How to ImplementTranslate XQuery in MarkLogic:
#adamretter http://www.adamretter.org.uk [email protected]
“going to investigate adding itto the ml-rest-lib project”- NDW
![Page 49: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/49.jpg)
RESTXQ
…status and thoughts
Now and Then
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]
![Page 50: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/50.jpg)
RESTXQ
XQuery 3.0 Annotations for REST
Now and ThenCurrent Status
#adamretter http://www.adamretter.org.uk [email protected]
• GET/POST/PUT/DELETE/HEAD • Params: form/query/header/cookie• Content Negotiation: Media Type• Serialization, static and dynamic• Supporting REST XQuery Module
^^ Implemented in eXist-db and BaseX
• %output:method(“binary”)• %output:method(“json”)• %output:method(“html5”)
![Page 51: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/51.jpg)
RESTXQ
XQuery 3.0 Annotations for REST
Now and ThenRoadmap
#adamretter http://www.adamretter.org.uk [email protected]
• Matrix Parameters • Multipart request and response
• Security Annotations
• SOAP Annotations
![Page 52: RESTXQ - Adam Retteradamretter.org.uk/presentations/restxq_mugl_20120308.pdf · RESTXQ • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter](https://reader031.vdocuments.mx/reader031/viewer/2022021911/5c28b2ca09d3f2563e8c3ac8/html5/thumbnails/52.jpg)
RESTXQ
…and maybe answers
Questions?
XQuery 3.0 Annotations for REST #adamretter http://www.adamretter.org.uk [email protected]