Linked RP works the same way Ratpack does - you provide a single Domain Specific Language (DSL) script where you write your methods to perform some function on a URL, and it weaves those in to a Jetty container. In this case, I've added some capabilities to Ratpack to work with linked data:
- RDFBuilder from Groovy SPARQL is automatically available to the DSL script under the 'rdf' variable
- link(String endpoint) is available as a function to get an instance of the Groovy SPARQL Sparql class for performing Sparql queries.
- resolve(String uri) is a new piece of functionality that uses Groovy's HTTPBuilder DSL and Jena to retrieve a URL and read it into RDF. It should work across various RDF serialization types, and likely bomb out on HTML or anything else if you feed it an incorrect URI
You can now browse to the following URLs:
Note: since Jena models being returned by those functions get automatically serialized back out - if you want to do serialization inline - return null
To get started with Linked Ratpack, you must do the following:
- Get Groovy SPARQL from Github, and build/install it with Gradle
- Get Linked Ratpack from Github, and build it
- Create simple groovy scripts, like the above gist, and run "ratpack path/to/whatever.groovy"
For me, this is one of the missing pieces in building linked data applications - an easy way to stand up little RDF servers to test walking RDF graphs hop-by-hop and perform URI de-referencing, and experimenting with generating derivative RDF sites from other RDF data sources (e.g. SPARQL Construct).
Many thanks to Justin Voss ( @ github ) for creating Ratpack in the first place, it was a solid foundation to build off of.