Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Creating Web APIs
with JSON-LD and RDF
About Me
Donald Smith
Sr. Software Engineer at Argo
Creating Web APIs
with JSON-LD and RDF
Why RESTful isn’t
enough…
Media Types
Atom

JSON

Collection+JSON

HAL

SIREN
Or…
Whatever I want!
These media types
are OK, but…
They don’t describe
my data
What is data?
Nothing without
applied meaning
Out of band
knowledge required
We want Information
not data
But JSON has won on
the web!
But, it’s not good
enough
A programmer adds
meaning to data
What if a machine could
understand information
instead?
RDF
What is RDF?
Resource Description
Framework
RDF is a standard model
for data interchange on
the Web
What does it do?
• Data merging even if underlying schemas differ
• Supports the evolution of schemas over time
without re...
The Basics
The Triple
Think of a sentence
written by a first grader
Donald owns a dog.

His name is Barley.
Yes, I like beer
a lot
Triple Composition
• Made up of three parts (hence Triple)
• The Subject
• The Predicate
• The Object
Sentence To Triple
Donald owns a dog.
subject predicate object
<Donald> <owns> <Barley>
subject predicate object
Um, this doesn’t look
better than JSON
Universal Uniqueness
• Triples use IRIs to uniquely identify Things in the Universe.
• IRIs allow us to use terms that are...
Expressed as a graph
Donald Barley
subject predicate object
owns
As JSON
{
"id": "people/Donald",
"type": "Person",
"name": "Donald",
"owns": {
"id": "animal/Barley",
"type": "Dog",
"name...
As RDF
<http://example.com/people/Donald> <http://www.w3.org/
1999/02/22-rdf-syntax-ns#type> <http://schema.org/
Person> ....
Whoa, I thought you said
it was better than JSON?
That’s unreadable!
It even repeats itself!
GTFO!
Ok, ok. You’re right.
RDF was created for
machines. Not humans.
There is a solution.
Turtle!
Example in Turtle
@base <http://example.com/> .

@prefix schema: <http://schema.org/> .

@prefix db: <http://dbpedia.org/o...
Cool stuff?
• RDF is just a way of making statements about
Things.
• There is no order in RDF unlike JSON objects.
• To as...
RDF allows us to say
anything about any Thing
in the Universe.
Whatever man, this stuff
looks confusing and
stupid. I’ll stick to JSON.
That’s ok. That’s cool.
Some smart guys thought
you’d say that.
JSON-LD
• The goal was to require as little effort as possible
from developers
• There are a ton of web APIs out there. Ch...
JSON-LD Context
{
"@context": {
"id": "@id",
"type": "@type",
"@base": "http://example.com/",
"Dog": "http://dbpedia.org/o...
The JSON object is
preserved. Existing
applications won’t break.
Let’s take a look…
Questions?
Media Types
• JSON-LD: application/ld+json
• Turtle: text/turtle
• N-Triples: application/n-triples
• N-Quads: application...
No need for another media
type
• The media type isn’t that relevant anymore
• Any schema or data model can be described wi...
JSON Web APIs
• Existing Web APIs can leverage JSON-LD to
promote data exchange between Applications
• Existing Web APIs t...
JSON-LD Expansion &
Compaction
Merging data sources
My website Mike’s website
{
"@context": {
"id": "@id",
"type": "@type",
"@base": "http://donald.com/"...
Expansion
• Each one is sent through the expansion algorithm
to output RDF
<http://mike.com/canine/Bob> <http://schema.org...
Merge the triples into a
Single Graph
<http://donald.com/animal/Barley> <http://schema.org/givenName> "Barley" .
<http://d...
Compaction with different
Context
"@context": {
"id": "@id",
"type": "@type",
"doggy": "http://dbpedia.org/ontology/Dog",
...
{
"@context": {
"id": "@id",
"type": "@type",
"doggy": "http://dbpedia.org/ontology/Dog",
"peeple": "http://schema.org/Per...
Questions?
Web APIs
• So far we only have looked at resolving unlike
terms into uniform machine readable URIs
• How do we build an AP...
Hydra
No, not this one
Hydra
Hydra
• Currently a W3C draft specification
• Hydra is a lightweight vocabulary to create
hypermedia-driven Web APIs. By sp...
Let’s take a look…
Thanks!
Creating Web APIs with JSON-LD and RDF
Upcoming SlideShare
Loading in …5
×

Creating Web APIs with JSON-LD and RDF

A brief look into building Web APIs with RDF, JSON-LD, and Hydra.

  • Be the first to comment

  • Be the first to like this

Creating Web APIs with JSON-LD and RDF

  1. 1. Creating Web APIs with JSON-LD and RDF
  2. 2. About Me Donald Smith Sr. Software Engineer at Argo
  3. 3. Creating Web APIs with JSON-LD and RDF
  4. 4. Why RESTful isn’t enough…
  5. 5. Media Types Atom
 JSON
 Collection+JSON
 HAL
 SIREN Or… Whatever I want!
  6. 6. These media types are OK, but…
  7. 7. They don’t describe my data
  8. 8. What is data?
  9. 9. Nothing without applied meaning
  10. 10. Out of band knowledge required
  11. 11. We want Information not data
  12. 12. But JSON has won on the web!
  13. 13. But, it’s not good enough
  14. 14. A programmer adds meaning to data
  15. 15. What if a machine could understand information instead?
  16. 16. RDF
  17. 17. What is RDF?
  18. 18. Resource Description Framework
  19. 19. RDF is a standard model for data interchange on the Web
  20. 20. What does it do? • Data merging even if underlying schemas differ • Supports the evolution of schemas over time without requiring consumers to change • Eliminates data silos between your applications • Allows you to ask questions of your data in a standard way
  21. 21. The Basics
  22. 22. The Triple
  23. 23. Think of a sentence written by a first grader
  24. 24. Donald owns a dog.
 His name is Barley.
  25. 25. Yes, I like beer
  26. 26. a lot
  27. 27. Triple Composition • Made up of three parts (hence Triple) • The Subject • The Predicate • The Object
  28. 28. Sentence To Triple Donald owns a dog. subject predicate object
  29. 29. <Donald> <owns> <Barley> subject predicate object
  30. 30. Um, this doesn’t look better than JSON
  31. 31. Universal Uniqueness • Triples use IRIs to uniquely identify Things in the Universe. • IRIs allow us to use terms that are specific and universal • IRIs are URIs, but internationalized
  32. 32. Expressed as a graph Donald Barley subject predicate object owns
  33. 33. As JSON { "id": "people/Donald", "type": "Person", "name": "Donald", "owns": { "id": "animal/Barley", "type": "Dog", "name": "Barley" } }
  34. 34. As RDF <http://example.com/people/Donald> <http://www.w3.org/ 1999/02/22-rdf-syntax-ns#type> <http://schema.org/ Person> .
 <http://example.com/people/Donald> <http://schema.org/ givenName> "Donald"^^xsd:string .
 <http://example.com/people/Donald> <http://schema.org/ owns> <http://example.com/animals/Rover> .
 <http://example.com/animals/Barley> <http://www.w3.org/ 1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ ontology/Dog> .
 <http://example.com/animals/Barley> <http://schema.org/ givenName> "Barley"^^xsd:string .
  35. 35. Whoa, I thought you said it was better than JSON? That’s unreadable!
  36. 36. It even repeats itself!
  37. 37. GTFO!
  38. 38. Ok, ok. You’re right.
  39. 39. RDF was created for machines. Not humans.
  40. 40. There is a solution. Turtle!
  41. 41. Example in Turtle @base <http://example.com/> .
 @prefix schema: <http://schema.org/> .
 @prefix db: <http://dbpedia.org/ontology/> .
 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
 
 <people/Donald> a schema:Person ;
 schema:givenName "Donald"^^xsd:string ;
 schema:owns <animals/Barley> .
 
 <animals/Barley> a db:Dog ;
 schema:givenName "Barley"^^xsd:string .
  42. 42. Cool stuff? • RDF is just a way of making statements about Things. • There is no order in RDF unlike JSON objects. • To assert information about a given subject, you don’t have to know where in the hierarchy that it exists. We just use the subjects IRI.
  43. 43. RDF allows us to say anything about any Thing in the Universe.
  44. 44. Whatever man, this stuff looks confusing and stupid. I’ll stick to JSON.
  45. 45. That’s ok. That’s cool. Some smart guys thought you’d say that.
  46. 46. JSON-LD • The goal was to require as little effort as possible from developers • There are a ton of web APIs out there. Changing to a new format would break a lot of stuff • JSON-LD lets us add semantic meaning without breaking.
  47. 47. JSON-LD Context { "@context": { "id": "@id", "type": "@type", "@base": "http://example.com/", "Dog": "http://dbpedia.org/ontology/Dog", "Person": "http://schema.org/Person", "name": "http://schema.org/givenName", "owns": "http://schema.org/owns" }, "id": "people/Donald", "type": "Person", "name": "Donald", "owns": { "id": "animal/Barley", "type": "Dog", "name": "Barley" } }
  48. 48. The JSON object is preserved. Existing applications won’t break.
  49. 49. Let’s take a look…
  50. 50. Questions?
  51. 51. Media Types • JSON-LD: application/ld+json • Turtle: text/turtle • N-Triples: application/n-triples • N-Quads: application/n-quads • RDF/XML: application/rdf+xml (Don’t use this one)
  52. 52. No need for another media type • The media type isn’t that relevant anymore • Any schema or data model can be described with RDF. • Think of it as a language that everyone speaks.
  53. 53. JSON Web APIs • Existing Web APIs can leverage JSON-LD to promote data exchange between Applications • Existing Web APIs that don’t or won’t support JSON-LD is ok too. You can inject an @context into a JSON fragment using out-of-band knowledge and still use it as RDF • JSON-LD supports both expansion and compaction
  54. 54. JSON-LD Expansion & Compaction
  55. 55. Merging data sources My website Mike’s website { "@context": { "id": "@id", "type": "@type", "@base": "http://donald.com/", "Dog": "http://dbpedia.org/ontology/Dog", "Person": "http://schema.org/Person", "name": "http://schema.org/givenName", "owns": "http://schema.org/owns" }, "id": "people/Donald", "type": "Person", "name": "Donald", "owns": { "id": "animal/Barley", "type": "Dog", "name": "Barley" } } { "@context": { "identifier": "@id", "objectType": "@type", "@base": "http://mike.com/", "canine": "http://dbpedia.org/ontology/Dog", "human": "http://schema.org/Person", "called": "http://schema.org/givenName", "ownerOf": "http://schema.org/owns" }, "identifier": "me", "objectType": "human", "called": "Mike", "ownerOf": { "identifier": "canine/Bob", "objectType": "canine", "called": "Bob" } }
  56. 56. Expansion • Each one is sent through the expansion algorithm to output RDF <http://mike.com/canine/Bob> <http://schema.org/givenName> "Bob" . <http://mike.com/canine/Bob> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Dog> . <http://mike.com/me> <http://schema.org/givenName> "Mike" . <http://mike.com/me> <http://schema.org/owns> <http://mike.com/canine/Bob> . <http://mike.com/me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . <http://donald.com/animal/Barley> <http://schema.org/givenName> "Barley" . <http://donald.com/animal/Barley> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Dog> . <http://donald.com/people/Donald> <http://schema.org/givenName> "Donald" . <http://donald.com/people/Donald> <http://schema.org/owns> <http://donald.com/animal/Barley> . <http://donald.com/people/Donald> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . My website Mike’s website
  57. 57. Merge the triples into a Single Graph <http://donald.com/animal/Barley> <http://schema.org/givenName> "Barley" . <http://donald.com/animal/Barley> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Dog> . <http://donald.com/people/Donald> <http://schema.org/givenName> "Donald" . <http://donald.com/people/Donald> <http://schema.org/owns> <http://donald.com/animal/Barley> . <http://donald.com/people/Donald> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> . <http://mike.com/canine/Bob> <http://schema.org/givenName> "Bob" . <http://mike.com/canine/Bob> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Dog> . <http://mike.com/me> <http://schema.org/givenName> "Mike" . <http://mike.com/me> <http://schema.org/owns> <http://mike.com/canine/Bob> . <http://mike.com/me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
  58. 58. Compaction with different Context "@context": { "id": "@id", "type": "@type", "doggy": "http://dbpedia.org/ontology/Dog", "peeple": "http://schema.org/Person", "namey": "http://schema.org/givenName", "hazIt": "http://schema.org/owns" }
  59. 59. { "@context": { "id": "@id", "type": "@type", "doggy": "http://dbpedia.org/ontology/Dog", "peeple": "http://schema.org/Person", "namey": "http://schema.org/givenName", "hazIt": "http://schema.org/owns" }, "@graph": [ { "id": "http://donald.com/people/Donald", "type": "peeple", "namey": "Donald", "hazIt": { "id": "http://donald.com/animal/Barley" } }, { "id": "http://mike.com/canine/Bob", "type": "doggy", "namey": "Bob" }, { "id": "http://mike.com/me", "type": "peeple", "namey": "Mike", "hazIt": { "id": "http://mike.com/canine/Bob" } }, { "id": "http://donald.com/animal/Barley", "type": "doggy", "namey": "Barley" } ] }
  60. 60. Questions?
  61. 61. Web APIs • So far we only have looked at resolving unlike terms into uniform machine readable URIs • How do we build an API with this stuff?
  62. 62. Hydra No, not this one
  63. 63. Hydra
  64. 64. Hydra • Currently a W3C draft specification • Hydra is a lightweight vocabulary to create hypermedia-driven Web APIs. By specifying a number of concepts commonly used in Web APIs it enables the creation of generic API clients.
  65. 65. Let’s take a look…
  66. 66. Thanks!

×