You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
6.4 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. XRay
  2. ====
  3. ## Discovering Content
  4. The contents of the URL is checked in the following order:
  5. * A supported silo URL (coming soon)
  6. * h-entry, h-event, h-card
  7. * OEmbed (coming soon)
  8. * OGP (coming soon)
  9. ## Parse API
  10. To parse a page and return structured data for the contents of the page, simply pass a url to the parse route.
  11. ```
  12. GET /parse?url=https://aaronparecki.com/2016/01/16/11/
  13. ```
  14. To conditionally parse the page after first checking if it contains a link to a target URL, also include the target URL as a parameter. This is useful if using XRay to verify an incoming webmention.
  15. ```
  16. GET /parse?url=https://aaronparecki.com/2016/01/16/11/&target=http://example.com
  17. ```
  18. In both cases, the response will be a JSON object containing a key of "type". If there was an error, "type" will be set to the string "error", otherwise it will refer to the kind of content that was found at the URL, most often "entry".
  19. You can also make a POST request with the same parameter names.
  20. ### Authentication
  21. If the URL you are fetching requires authentication, include the access token in the parameter "token", and it will be included in an "Authorization" header when fetching the URL. (It is recommended to use a POST request in this case, to avoid the access token potentially being logged as part of the query string.)
  22. ```
  23. POST /parse
  24. url=https://aaronparecki.com/2016/01/16/11/
  25. &target=http://example.com
  26. &token=12341234123412341234
  27. ```
  28. ### Error Response
  29. ```json
  30. {
  31. "error": "not_found",
  32. "error_description": "The URL provided was not found"
  33. }
  34. ```
  35. Possible errors are listed below:
  36. * `not_found`: The URL provided was not found. (Returned 404 when fetching)
  37. * `ssl_cert_error`: There was an error validating the SSL certificate. This may happen if the SSL certificate has expired.
  38. * `ssl_unsupported_cipher`: The web server does not support any of the SSL ciphers known by the service.
  39. * `timeout`: The service timed out trying to connect to the URL.
  40. * `invalid_content`: The content at the URL was not valid. For example, providing a URL to an image will return this error.
  41. * `no_link_found`: The target link was not found on the page. When a target parameter is provided, this is the error that will be returned if the target could not be found on the page.
  42. * `no_content`: No usable content could be found at the given URL.
  43. * `unauthorized`: The URL returned HTTP 401 Unauthorized.
  44. * `forbidden`: The URL returned HTTP 403 Forbidden.
  45. ### Response Format
  46. ```json
  47. {
  48. "data": {
  49. "type": "entry",
  50. "author": {
  51. "type": "card",
  52. "name": "Aaron Parecki",
  53. "photo": "https://aaronparecki.com/images/aaronpk-256.jpg",
  54. "url": "https://aaronparecki.com/"
  55. },
  56. "url": "https://aaronparecki.com/2016/01/16/11/",
  57. "published": "2016-01-16T16:26:43-08:00",
  58. "photo": [
  59. "https://aaronparecki.com/2016/01/16/11/photo.png"
  60. ],
  61. "syndication": [
  62. "https://twitter.com/aaronpk/status/688518372170977280"
  63. ],
  64. "summary": "Now that @MozillaPersona is shutting down, the only good way to do email-based login is how @poetica does it.",
  65. "content": {
  66. "html": "Now that <a href=\"https://twitter.com/MozillaPersona\">@MozillaPersona</a> is shutting down, the only good way to do email-based login is how <a href=\"https://twitter.com/poetica\">@poetica</a> does it.",
  67. "text": "Now that @MozillaPersona is shutting down, the only good way to do email-based login is how @poetica does it."
  68. },
  69. }
  70. }
  71. ```
  72. If a property supports multiple values, it will always be returned as an array. The following properties support multiple values:
  73. * in-reply-to
  74. * syndication
  75. * photo (of entry, not of a card)
  76. The content will be an object that always contains a "text" property and may contain an "html" property if the source documented published HTML content. The "text" property must always be HTML escaped before displaying it as HTML, as it may include unescaped characters such as `<` and `>`.
  77. The author will always be set in the entry if available. The service follows the [authorship discovery](http://indiewebcamp.com/authorship) algorithm to try to find the author information elsewhere on the page if it is not inside the entry in the source document.
  78. All URLs provided in the output are absolute URLs. If the source document contains a relative URL, it will be resolved first.
  79. In a future version, replies, likes, reposts, etc. of this post will be included if they are listed on the page.
  80. ```json
  81. {
  82. "data": {
  83. "type": "entry",
  84. ...
  85. "like": [
  86. {
  87. "type": "cite",
  88. "author": {
  89. "type": "card",
  90. "name": "Thomas Dunlap",
  91. "photo": "https://s3-us-west-2.amazonaws.com/aaronparecki.com/twitter.com/9055c458a67762637c0071006b16c78f25cb610b224dbc98f48961d772faff4d.jpeg",
  92. "url": "https://twitter.com/spladow"
  93. },
  94. "url": "https://twitter.com/aaronpk/status/688518372170977280#favorited-by-16467582"
  95. }
  96. ],
  97. "comment": [
  98. {
  99. "type": "cite",
  100. "author": {
  101. "type": "card",
  102. "name": "Poetica",
  103. "photo": "https://s3-us-west-2.amazonaws.com/aaronparecki.com/twitter.com/192664bb706b2998ed42a50a860490b6aa1bb4926b458ba293b4578af599aa6f.png",
  104. "url": "http://poetica.com/"
  105. },
  106. "url": "https://twitter.com/poetica/status/689045331426803712",
  107. "published": "2016-01-18T03:23:03-08:00",
  108. "content": {
  109. "text": "@aaronpk @mozillapersona thanks very much! :)"
  110. }
  111. }
  112. ]
  113. }
  114. }
  115. ```
  116. ## Token API
  117. When verifying [Private Webmentions](https://indieweb.org/Private-Webmention#How_to_Receive_Private_Webmentions), you will need to exchange a code for an access token at the token endpoint specified by the source URL.
  118. XRay provides an API that will do this in one step. You can provide the source URL and code you got from the webmention, and XRay will discover the token endpoint, and then return you an access token.
  119. ```
  120. POST /token
  121. source=http://example.com/private-post
  122. &code=1234567812345678
  123. ```
  124. The response will be the response from the token endpoint, which will include an `access_token` property, and possibly an `expires_in` property.
  125. ```
  126. {
  127. "access_token": "eyJ0eXAXBlIjoI6Imh0dHB8idGFyZ2V0IjoraW0uZGV2bb-ZO6MV-DIqbUn_3LZs",
  128. "token_type": "bearer",
  129. "expires_in": 3600
  130. }
  131. ```
  132. If there was a problem fetching the access token, you will get one of the errors below in addition to the HTTP related errors returned by the parse API:
  133. * `no_token_endpoint` - Unable to find an HTTP header specifying the token endpoint.