Leigh Dodds @ldodds http://kasabi.com Creating APIs over RDF Data Sources 8 th  June 2011. SemTech 2011
The Trouble with SPARQL
Try our SPARQL Endpoint! Run Query
http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=SELECT+%3Fresult+FROM+%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FBMW_Z8%3E+WHERE+{+%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FBMW_Z8%3E+dbpprop%3Aname+%3Fresult+.+FILTER+%28LANG%28%3Fresult%29+%3D+%27en%27%29+.}&debug=on&timeout=&format=text%2Fhtml&save=display&fname= Trial and error experiments aren't easy
APIs have Affordance They're like pulling a thread The URLs unravel into useful data
http://api.simplegeo.com/1.0/context/{lat},{lon}.json Trial and error experiments are easy
SPARQL is for Power Users
How can we give RDF datasets more affordance?
Linked Data? Typically not expressive enough to support all useful interactions Expensive to materialize all useful data partitions E.g. by date-time, location, top ranking, etc
Build Custom APIs? Write custom code against your graph store Can be expensive to build & maintain Undermines power of web of data
OData? Standard data API from Microsoft Very similar to RDF & Linked Data approach Can be implemented over SPARQL endpoint
SPARQL Stored Procedures & The Linked Data API
SPARQL “Stored Procedures”
Bind SPARQL query to a URL http://api.kasabi.com/api/find-recipe-ingredient?ingredient={x}
More than just a URL shortener 1. Identify query bound to URL 2. Inject parameters from URL & config 3. Apply paging/sorting options 4. Execute query 5. Optionally, apply post-processing transformations
Parameter Passing Optional and Required Parameters Mapping to a particular type of RDF Term, e.g. literal, URI May have a default value May have a default prefix, e.g. base URL
Post-Processing Named transformations that generate a specific mime-type Supports generating custom output formats Currently just XSLT. Could support JS
Stored Procedure Benefits Declarative approach Offers simpler interface to developers Retains RDF output, but supports custom formats
The Linked Data API
Linked Data API http://purl.org/linked-data/api/spec Jeni Tennison (TSO), Dave Reynolds (Epimorphics), Leigh Dodds
Linked Data API Map parameterised URLs to graph queries to extract data views
Linked Data API Optimize for common query patterns Prioritize simple RESTful interactions not complex queries Provide pathway to exploring RDF and SPARQL
Processing Model Select View Request Response Format SPARQL Endpoint SELECT ?item  WHERE { … } Endpoint DESCRIBE <x> <y>  API Config
Selecting Resources URL mapped to query patterns by API configuration Query variables injected from URL path or query string Simple path expressions for traversing graph Support for sorting and paging
Viewing Resources Default “view” is Concise Bounded Description Can specify arbitrary collections of properties in config or URL
Output Formats Simple JSON and XML formats Standard RDF serializations Custom formats, including HTML, via XSLT
@prefix spec:   <http://api.kasabi.com/api/foodista-lda/> . @prefix api:  <http://purl.org/linked-data/api/vocab#> . @prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> . @prefix recipe:  <http://linkedrecipes.org/schema/> . spec:api a api:API ; api:defaultPageSize &quot;10&quot; ; api:endpoint spec:foods . spec:foods a api:ListEndpoint ; api:uriTemplate &quot;/foods&quot; ; api:selector [  api:filter &quot;type=Food&quot; ]; api:defaultViewer api:describeViewer . rdf:type api:label &quot;type&quot; . recipe:Food api:label &quot;Food&quot; .
{ &quot;format&quot;: &quot;linked-data-api&quot;, &quot;version&quot;: &quot;0.2&quot; &quot;result&quot;: { &quot;items&quot;: [ { &quot;label&quot;: &quot;Balsamic Vinegar&quot;, &quot;isPrimaryTopicOf&quot;: &quot;http://www.foodista.com/food/23HWFLXY &quot;type&quot;: &quot;http://linkedrecipes.org/schema/Food&quot;, &quot;_about&quot;: &quot;http://data.kasabi.com/dataset/foodista/food/23HWFLXY&quot;, &quot;description&quot;: &quot;Balsamic Vinegar is...&quot; },   ... ], &quot;modified&quot;: &quot;Monday, 06-Jun-11 19:15:43 UTC&quot;, &quot;itemsPerPage&quot;: 10, &quot;startIndex&quot;: 0, &quot;type&quot;: &quot;http://purl.org/linked-data/api/vocab#Page&quot;, &quot;first&quot;: &quot;/api/foodista-linked-data-api/foods.json?_page=1&quot;, &quot;_about&quot;: &quot;/api/foodista-linked-data-api/foods.json?_page=1&quot;, &quot;next&quot;: &quot;/api/foodista-linked-data-api/foods.json?_page=2&quot;, ... }
Open Source Implementations Puelia (PHP) http://code.google.com/p/puelia-php/ Elda (Java) http://code.google.com/p/elda/
Linked Data API Summary Declarative configuration-driven approach More sophisticated than SSPs Integrates well with Linked Data publishing Slightly higher learning curve
Summary
Adopt hybrid approach to encourage adoption Combine Linked Data with SPARQL  powered  APIs Recognise need for bridging, adapting between tools/systems/communities
Support a “view source” approach  Enable Crowd-Sourcing of APIs by sharing configuration & queries
Try It For Yourself! http://beta.kasabi.com Linked Data, RDF and API hosting Demo: 9.30 tomorrow
 

Creating APIs over RDF

  • 1.
    Leigh Dodds @ldoddshttp://kasabi.com Creating APIs over RDF Data Sources 8 th June 2011. SemTech 2011
  • 2.
  • 3.
    Try our SPARQLEndpoint! Run Query
  • 4.
  • 5.
    APIs have AffordanceThey're like pulling a thread The URLs unravel into useful data
  • 6.
  • 7.
    SPARQL is forPower Users
  • 8.
    How can wegive RDF datasets more affordance?
  • 9.
    Linked Data? Typicallynot expressive enough to support all useful interactions Expensive to materialize all useful data partitions E.g. by date-time, location, top ranking, etc
  • 10.
    Build Custom APIs?Write custom code against your graph store Can be expensive to build & maintain Undermines power of web of data
  • 11.
    OData? Standard dataAPI from Microsoft Very similar to RDF & Linked Data approach Can be implemented over SPARQL endpoint
  • 12.
    SPARQL Stored Procedures& The Linked Data API
  • 13.
  • 14.
    Bind SPARQL queryto a URL http://api.kasabi.com/api/find-recipe-ingredient?ingredient={x}
  • 15.
    More than justa URL shortener 1. Identify query bound to URL 2. Inject parameters from URL & config 3. Apply paging/sorting options 4. Execute query 5. Optionally, apply post-processing transformations
  • 16.
    Parameter Passing Optionaland Required Parameters Mapping to a particular type of RDF Term, e.g. literal, URI May have a default value May have a default prefix, e.g. base URL
  • 17.
    Post-Processing Named transformationsthat generate a specific mime-type Supports generating custom output formats Currently just XSLT. Could support JS
  • 18.
    Stored Procedure BenefitsDeclarative approach Offers simpler interface to developers Retains RDF output, but supports custom formats
  • 19.
  • 20.
    Linked Data APIhttp://purl.org/linked-data/api/spec Jeni Tennison (TSO), Dave Reynolds (Epimorphics), Leigh Dodds
  • 21.
    Linked Data APIMap parameterised URLs to graph queries to extract data views
  • 22.
    Linked Data APIOptimize for common query patterns Prioritize simple RESTful interactions not complex queries Provide pathway to exploring RDF and SPARQL
  • 23.
    Processing Model SelectView Request Response Format SPARQL Endpoint SELECT ?item WHERE { … } Endpoint DESCRIBE <x> <y> API Config
  • 24.
    Selecting Resources URLmapped to query patterns by API configuration Query variables injected from URL path or query string Simple path expressions for traversing graph Support for sorting and paging
  • 25.
    Viewing Resources Default“view” is Concise Bounded Description Can specify arbitrary collections of properties in config or URL
  • 26.
    Output Formats SimpleJSON and XML formats Standard RDF serializations Custom formats, including HTML, via XSLT
  • 27.
    @prefix spec: <http://api.kasabi.com/api/foodista-lda/> . @prefix api: <http://purl.org/linked-data/api/vocab#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix recipe: <http://linkedrecipes.org/schema/> . spec:api a api:API ; api:defaultPageSize &quot;10&quot; ; api:endpoint spec:foods . spec:foods a api:ListEndpoint ; api:uriTemplate &quot;/foods&quot; ; api:selector [ api:filter &quot;type=Food&quot; ]; api:defaultViewer api:describeViewer . rdf:type api:label &quot;type&quot; . recipe:Food api:label &quot;Food&quot; .
  • 28.
    { &quot;format&quot;: &quot;linked-data-api&quot;,&quot;version&quot;: &quot;0.2&quot; &quot;result&quot;: { &quot;items&quot;: [ { &quot;label&quot;: &quot;Balsamic Vinegar&quot;, &quot;isPrimaryTopicOf&quot;: &quot;http://www.foodista.com/food/23HWFLXY &quot;type&quot;: &quot;http://linkedrecipes.org/schema/Food&quot;, &quot;_about&quot;: &quot;http://data.kasabi.com/dataset/foodista/food/23HWFLXY&quot;, &quot;description&quot;: &quot;Balsamic Vinegar is...&quot; }, ... ], &quot;modified&quot;: &quot;Monday, 06-Jun-11 19:15:43 UTC&quot;, &quot;itemsPerPage&quot;: 10, &quot;startIndex&quot;: 0, &quot;type&quot;: &quot;http://purl.org/linked-data/api/vocab#Page&quot;, &quot;first&quot;: &quot;/api/foodista-linked-data-api/foods.json?_page=1&quot;, &quot;_about&quot;: &quot;/api/foodista-linked-data-api/foods.json?_page=1&quot;, &quot;next&quot;: &quot;/api/foodista-linked-data-api/foods.json?_page=2&quot;, ... }
  • 29.
    Open Source ImplementationsPuelia (PHP) http://code.google.com/p/puelia-php/ Elda (Java) http://code.google.com/p/elda/
  • 30.
    Linked Data APISummary Declarative configuration-driven approach More sophisticated than SSPs Integrates well with Linked Data publishing Slightly higher learning curve
  • 31.
  • 32.
    Adopt hybrid approachto encourage adoption Combine Linked Data with SPARQL powered APIs Recognise need for bridging, adapting between tools/systems/communities
  • 33.
    Support a “viewsource” approach Enable Crowd-Sourcing of APIs by sharing configuration & queries
  • 34.
    Try It ForYourself! http://beta.kasabi.com Linked Data, RDF and API hosting Demo: 9.30 tomorrow
  • 35.