• Save
Building Next-Generation Web APIs with JSON-LD and Hydra
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Building Next-Generation Web APIs with JSON-LD and Hydra

  • 10,027 views
Uploaded on

Presented at the Symfony Live Portland 2013 in Portland (Oregon), USA ...

Presented at the Symfony Live Portland 2013 in Portland (Oregon), USA
The recording of the talk is available at http://bit.ly/sl-portland2013-video

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
10,027
On Slideshare
9,825
From Embeds
202
Number of Embeds
7

Actions

Shares
Downloads
1
Comments
0
Likes
36

Embeds 202

http://lanyrd.com 103
https://twitter.com 71
http://librosweb.es 18
http://www.linkedin.com 7
http://librosweb.dev 1
https://www.linkedin.com 1
http://syncer.jp 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Building Next-Gen Web APIswith JSON-LD and HydraMarkus Lanthaler
  • 2. Why do weneed a website?Of course wehave a websiteWhy do weneed an API?1995 2000 2005 2010Of course wehave an APIAdapted from T. Vitvar’s and J. Musser’s ECOWS 2010 Keynote,“ProgrammableWeb.com:Statistics, Trends, and Best Practices”
  • 3. Using Web APIs is still challenging
  • 4. Level 0:The Swamp of POXLevel 1: ResourcesLevel 2: HTTPVerbs
  • 5. {"id": "cso29ax","title": "Symfony Live Portland 2013","description": "Prepare slides","is_open": true,"created_at": "2012-11-26T04:49:44Z"}http://example.com/issues/cso29ax
  • 6. BILLION DOLLARQUESTIONthe
  • 7. {"id": "cso29ax","title": "Symfony Live Portland 2013","description": "Prepare slides","is_open": true,"created_at": "2012-11-26T04:49:44Z"}http://example.com/issues/cso29axhttp://example.com/issue/{id}/comments/
  • 8. {"id": "cso29ax","title": "Symfony Live Portland 2013","description": "Prepare slides","is_open": true,"created_at": "2012-11-26T04:49:44Z","comments": "/issues/cso29ax/comments/"}http://example.com/issues/cso29ax
  • 9. Level 0:The Swamp of POXLevel 1: ResourcesLevel 2: HTTPVerbsLevel 3: Hypermedia Controls
  • 10. {"id": "cso29ax","title": "Symfony Live Portland 2013","description": "Prepare slides","is_open": true,"created_at": "2012-11-26T04:49:44Z","comments": "/issues/cso29ax/comments/"}http://example.com/issues/cso29ax
  • 11. Every API is a snowflake
  • 12. Result: tightly coupled & brittle systems
  • 13. {"id": "cso29ax","title": "Symfony Live Portland 2013","description": "Prepare slides","is_open": true,"created_at": "2012-11-26T04:49:44Z","comments": "/issues/cso29ax/comments/"}http://example.com/issues/cso29ax
  • 14. {69 64: 63 73 6f 32 39 61 7874 69 74 6c 65: 53 79 6d 66 6f 6e 79 20 4c 69 76 …64 65 73 63 72 69 70 74 69 6f 6e: 50 72 65 70 61 …69 73 5f 6f 70 65 6e: 0163 72 65 61 74 65 64 5f 61 74: 32 30 31 32 2d 31 …63 6f 6d 6d 65 6e 74 73: 2f 69 73 73 75 65 73 2f …}http://example.com/issues/cso29ax
  • 15. Identifiers on the Web: URIs
  • 16. Linked Data PrinciplesTim Berners-Lee, 2006
  • 17. JSON-LD
  • 18. Make data self-descriptive bymapping concepts to URLs
  • 19. {"id": "markus","firstname": "Markus","lastname": "Lanthaler","homepage": "http://www.markus-lanthaler.com/"}
  • 20. {"@context": {"firstname": "http://schema.org/givenName","lastname": "http://schema.org/familyName","homepage": "http://schema.org/url"},"id": "markus","firstname": "Markus","lastname": "Lanthaler","homepage": "http://www.markus-lanthaler.com/"}
  • 21. {"@context": {"firstname": "http://schema.org/givenName","lastname": "http://schema.org/familyName","homepage": "http://schema.org/url"},"@id": "/people/markus","firstname": "Markus","lastname": "Lanthaler","homepage": "http://www.markus-lanthaler.com/"}
  • 22. {"@context": {"firstname": "http://schema.org/givenName","lastname": "http://schema.org/familyName","homepage": "http://schema.org/url"},"@id": "/people/markus","firstname": "Markus","lastname": "Lanthaler","homepage": "http://www.markus-lanthaler.com/"}
  • 23. {"@context": {"firstname": "http://schema.org/givenName","lastname": "http://schema.org/familyName","homepage": "http://schema.org/url"},"@id": "/people/markus","firstname": "Markus","lastname": "Lanthaler","homepage": { "@id": "http://www.markus-lanthaler.com/" }}
  • 24. {"@context": {"firstname": "http://schema.org/givenName","lastname": "http://schema.org/familyName","homepage": {"@id": "http://schema.org/url", "@type": "@id" },},"@id": "/people/markus","firstname": "Markus","lastname": "Lanthaler","homepage": "http://www.markus-lanthaler.com/"}
  • 25. {"@context": {"firstname": "http://schema.org/givenName","lastname": "http://schema.org/familyName","homepage": {"@id": "http://schema.org/url", "@type": "@id" }},"@id": "/people/markus","@type": "http://schema.org/Person","firstname": "Markus","lastname": "Lanthaler","homepage": "http://www.markus-lanthaler.com/"}
  • 26. {"@context": {"firstname": "http://schema.org/givenName","lastname": "http://schema.org/familyName","homepage": {"@id": "http://schema.org/url", "@type": "@id" }},"@id": "/people/markus","@type": "http://schema.org/Person","firstname": "Markus","lastname": "Lanthaler","homepage": "http://www.markus-lanthaler.com/"}
  • 27. {"@context": "/contexts/person.jsonld","@id": "/people/markus","@type": "http://schema.org/Person","firstname": "Markus","lastname": "Lanthaler","homepage": "http://www.markus-lanthaler.com/"}
  • 28. CMF
  • 29. {"id": "cso29ax","title": "Symfony Live Portland 2013","description": "Prepare slides","is_open": true,"created_at": "2012-11-26T04:49:44Z","comments": "/issues/cso29ax/comments/"}http://example.com/issues/cso29ax
  • 30. {"@context": "/ctx/context.jsonld","id": "cso29ax","title": "Symfony Live Portland 2013","description": "Prepare slides","is_open": true,"created_at": "2012-11-26T04:49:44Z","comments": "/issues/cso29ax/comments/"}http://example.com/issues/cso29ax
  • 31. {"@context": "/ctx/context.jsonld","id": "cso29ax","title": "Symfony Live Portland 2013","description": "Prepare slides","is_open": true,"created_at": "2012-11-26T04:49:44Z","comments": "/issues/cso29ax/comments/"}http://example.com/issues/cso29ax
  • 32. {"@id": "#comments","@type": "hydra:Link","supportedOperations": [{"@id": "#create-comment","@type": "hydra:CreateResourceOperation","label": "Creates a new comment","method": "POST","expects": "#Comment","returns": "#Comment"}]}http://example.com/api/doc
  • 33. {"@id": "#Comment","@type": "hydra:Class","supportedProperties": [{"property": "#text","required": true,"readonly": false,"writeonly": false}]}http://example.com/api/doc
  • 34. /*** An Issue tracked by the system.** @HydraExpose()*/class Issue{/*** The comments associated with this issue** @HydraExpose()* @HydraCollection("issue_comments")* @HydraOperations("issue_comment_create")*/private $comments;// ... other members and methods ...}
  • 35. $ php app/console hydra:generate:crud--entity=MLDemoBundle:Issue--route-prefix=/issues/--with-write--no-interactionCRUD generationGenerating the CRUD code: OKYou can now start using the generated code!
  • 36. /*** Issue controller** @Route("/issues")*/class IssueController extends HydraController{/*** Creates a new Issue** @Route("/", name="issue_create")* @Method("POST")** @HydraOperation(expect = "MLDemoBundleEntityIssue")** @return MLDemoBundleEntityIssue*/public function collectionPostAction(Request $request){...
  • 37. Hydra Console
  • 38. © 2013, Markus Lanthaler. Some Rights Reserved.http://creativecommons.org/licenses/by-nc-sa/3.0/Thank You
  • 39. Questions?Markus Lanthalerhttp://www.markus-lanthaler.com@MarkusLanthalermail@markus-lanthaler.com
  • 40. Image Credits(1) http://www.flickr.com/photos/justinwkern/3729649672/(2) http://www.flickr.com/photos/alexdram/3095419858/(3) http://www.flickr.com/photos/kaptainkobold/3203311346/(11) http://info.cern.ch/hypertext/WWW/TheProject.html(15) Adapted from http://www.flickr.com/photos/nebarnix/361650027/(16) http://www.flickr.com/photos/joyoflife/1570126182/(19) http://www.flickr.com/photos/rossiprojects/5592552858/(21) http://www.flickr.com/photos/rossiprojects/5592552858/(23) http://www.flickr.com/photos/clevercupcakes/4397152402/(31) http://schema.org/Person(36) http://www.vonwong.com/(42) http://www.flickr.com/photos/jakecaptive/3205277810/(47) http://www.flickr.com/photos/sis/126152933/