+ All Categories
Home > Documents > RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension...

RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension...

Date post: 12-Jul-2020
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
38
Adam Retter XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected] RESTful XQuery XQuery 3.0 Annotations for REST
Transcript
Page 1: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

Adam Retter

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

RESTful XQueryXQuery 3.0

Annotations for REST

Page 2: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

1. The Problem!

2. The Solution?

3. Proof of Concept

Agenda

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

Page 3: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

…or, how I ended up here,

and why I care.

The Problem!

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

Page 4: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

The Problem!

Page 5: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

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 http://www.adamretter.org.uk [email protected]

The Problem!

Page 6: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• Implement W3C Standards

• Create/meet demand by adding value….

– Innovate

• Implementation features

• Language Extensions…

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

The Problem!Vendors Compete

Page 7: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

The Problem!Vendors Innovate

Page 8: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

Page 9: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

…or, XQuery Web App Examples

The Wheel Factory

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

Page 10: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

Page 11: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

wheel.xqm (1/2)

Page 12: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

wheel.xqm (2/2)

Page 13: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

Page 14: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

Page 15: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

The Wheel Factory Service

implemented in

eXist-db URL Rewrite

Page 16: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

controller.xql (1/2)

Page 17: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

controller.xql (2/2)

Page 18: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

The Wheel Factory Service

implemented in

MarkLogic REST Library

Page 19: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

rewriter.xqy

Page 20: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

endpoints.xqm (1/2)

Page 21: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

endpoints.xqm (2/2)

Page 22: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

wheel-proxy.xqm

Page 23: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

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 24: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

Page 25: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

…or, an approach that I came up with.

The Solution?

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

Page 26: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

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 http://www.adamretter.org.uk [email protected]

The Solution?Goals

Page 27: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

The Solution?RESTful Annotations

Page 28: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• Functions => Resource Functions– Constraint Annotations

– Parameter Annotations

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

The Solution?RESTful Annotations

Page 29: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

The Solution?RESTful Annotations

?

Page 30: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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(“{$body}”)

%rest:PUT(“{$body}”)

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

The Solution?RESTful Annotations

Page 31: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 ommitted, then default is */*

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

The Solution?RESTful Annotations

Page 32: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• Serialization– Resource - The result of the XQuery function

– HTTP Headers, Status Code and Description

• <rest:response>

– Both, Resource and HTTP Headers, Status and desc. • (<rest:response >…</rest:response>, $resource)

• Annotations based on W3C XSLT and XQuerySerialization 3.0

%output:method(“xhtml”)

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

The Solution?RESTful Annotations

Page 33: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

…demo of an implementation

Proof of Concept

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]

Page 34: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

The Wheel Factory Service

Re-inventing

RESTful Annotations

Page 35: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTfulwheel.xqm (1/2)

Page 36: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTfulwheel.xqm (2/2)

Page 37: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

• 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 http://www.adamretter.org.uk [email protected]

The Solution?Satisfies our Goals:

Page 38: RESTful XQuery - XML · RESTful XQuery • Extensions for accessing the Web Context – Extension functions e.g. Get HTTP Request Parameter • Implementation for Web Connectivity

RESTful XQuery

…and maybe answers

Questions?

XQuery 3.0 Annotations for REST http://www.adamretter.org.uk [email protected]


Recommended