# REST API's and querying a graph of objects

**URL:** <https://www.ruby-forum.com/t/rest-apis-and-querying-a-graph-of-objects/95849>\
**Category:** Rails\
**Created:** [January 20, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/rest-apis-and-querying-a-graph-of-objects/95849 "2006-01-20T17:26:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mperham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@mperham](https://www.ruby-forum.com/u/mperham)\
**Post date:** [January 20, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/rest-apis-and-querying-a-graph-of-objects/95849/1 "2006-01-20T17:26:10Z")

</div>

Hey all,

I am wondering if anyone has given thought to using REST / XPath as  
querying mechanism. That way you could have a URL that actually maps  
to a collection of records (objects, really) that meet a certain  
criteria and that are sorted a certain way.

Mike P.

---

<div class="post-metadata">

**Author:** ![mperham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@mperham](https://www.ruby-forum.com/u/mperham)\
**Post date:** [January 20, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/rest-apis-and-querying-a-graph-of-objects/95849/2 "2006-01-20T22:07:30Z")

</div>

I’ve seen that approach in the Java world. You have to be wary using it  
though, it opens you up to the possiblity of XPath Injection attacks.  
Similar to SQL Injection attacks in principle, not as potentially  
damaging  
though.

-Steve  
[http://www.stevelongdo.com](http://www.stevelongdo.com)

---

<div class="post-metadata">

**Author:** ![mperham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@mperham](https://www.ruby-forum.com/u/mperham)\
**Post date:** [January 20, 2006, 10:28pm UTC](https://www.ruby-forum.com/t/rest-apis-and-querying-a-graph-of-objects/95849/3 "2006-01-20T22:28:45Z")

</div>

Any Java projects doing this that spring to mind?

---

<div class="post-metadata">

**Author:** ![mperham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@mperham](https://www.ruby-forum.com/u/mperham)\
**Post date:** [January 21, 2006, 1:08am UTC](https://www.ruby-forum.com/t/rest-apis-and-querying-a-graph-of-objects/95849/4 "2006-01-21T01:08:51Z")

</div>

> Any Java projects doing this that spring to mind?

Hi Mike

I’ve been using JXPath ( [Apache Commons JXPath – JXPath Home](http://jakarta.apache.org/commons/jxpath/) ) for  
that purpose two years ago.

–Thibaut

=====================

The org.apache.commons.jxpath package defines a simple interpreter of an  
expression language called XPath. JXPath applies _XPath_ expressions to  
graphs of objects of all kinds: JavaBeans, Maps, Servlet contexts, DOM  
etc,  
including mixtures thereof.

Consider this example:

Address address = (Address)JXPathContext.newContext(vendor).  
getValue(“locations[address/zipCode=‘90210’]/address”);

This XPath expression is equvalent to the following Java code:

Address address = null;  
Collection locations = vendor.getLocations();  
Iterator it = locations.iterator();  
while (it.hasNext()){  
Location location = (Location)it.next();  
String zipCode = location.getAddress().getZipCode();  
if (zipCode.equals(“90210”)){  
address = location.getAddress();  
break;  
}

}

---

<div class="post-metadata">

**Author:** ![mperham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47c2d/32.png) [@mperham](https://www.ruby-forum.com/u/mperham)\
**Post date:** [January 20, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/rest-apis-and-querying-a-graph-of-objects/95849/5 "2006-01-20T23:08:09Z")

</div>

PMD - [http://pmd.sf.net](http://pmd.sf.net) - does something like this in that you can query  
a source file’s Abstract Syntax Tree using XPath. Like this to get all  
fields with the name “foo”:

//FieldDeclaration[@Image=‘foo’]

It’s a bit esoteric - PMD is a Java static analysis tool - but, it seems  
to fit the question…

Yours,

Tom

P.S. Disclaimer: I’m the PMD lead guy.
