idnits 2.17.1 draft-kelly-json-hal-05.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (February 12, 2013) is 4089 days in the past. Is this intentional? Checking references for intended status: Informational ---------------------------------------------------------------------------- ** Obsolete normative reference: RFC 4627 (Obsoleted by RFC 7158, RFC 7159) ** Obsolete normative reference: RFC 5988 (Obsoleted by RFC 8288) Summary: 2 errors (**), 0 flaws (~~), 1 warning (==), 1 comment (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group M. Kelly 3 Internet-Draft Stateless 4 Intended status: Informational February 12, 2013 5 Expires: August 16, 2013 7 JSON Hypertext Application Language 8 draft-kelly-json-hal-05 10 Abstract 12 This document proposes a media type for representing resources and 13 their relations with hyperlinks. 15 Status of This Memo 17 This Internet-Draft is submitted in full conformance with the 18 provisions of BCP 78 and BCP 79. 20 Internet-Drafts are working documents of the Internet Engineering 21 Task Force (IETF). Note that other groups may also distribute 22 working documents as Internet-Drafts. The list of current Internet- 23 Drafts is at http://datatracker.ietf.org/drafts/current/. 25 Internet-Drafts are draft documents valid for a maximum of six months 26 and may be updated, replaced, or obsoleted by other documents at any 27 time. It is inappropriate to use Internet-Drafts as reference 28 material or to cite them other than as "work in progress." 30 This Internet-Draft will expire on August 16, 2013. 32 Copyright Notice 34 Copyright (c) 2013 IETF Trust and the persons identified as the 35 document authors. All rights reserved. 37 This document is subject to BCP 78 and the IETF Trust's Legal 38 Provisions Relating to IETF Documents 39 (http://trustee.ietf.org/license-info) in effect on the date of 40 publication of this document. Please review these documents 41 carefully, as they describe your rights and restrictions with respect 42 to this document. Code Components extracted from this document must 43 include Simplified BSD License text as described in Section 4.e of 44 the Trust Legal Provisions and are provided without warranty as 45 described in the Simplified BSD License. 47 Table of Contents 48 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 49 2. Requirements . . . . . . . . . . . . . . . . . . . . . . . . 3 50 3. HAL Documents . . . . . . . . . . . . . . . . . . . . . . . . 3 51 4. Resource Objects . . . . . . . . . . . . . . . . . . . . . . 4 52 4.1. Reserved Properties . . . . . . . . . . . . . . . . . . . 4 53 4.1.1. _links . . . . . . . . . . . . . . . . . . . . . . . 4 54 4.1.2. _embedded . . . . . . . . . . . . . . . . . . . . . . 4 55 5. Link Objects . . . . . . . . . . . . . . . . . . . . . . . . 4 56 5.1. href . . . . . . . . . . . . . . . . . . . . . . . . . . 5 57 5.2. templated . . . . . . . . . . . . . . . . . . . . . . . . 5 58 5.3. type . . . . . . . . . . . . . . . . . . . . . . . . . . 5 59 5.4. deprecation . . . . . . . . . . . . . . . . . . . . . . . 5 60 5.5. name . . . . . . . . . . . . . . . . . . . . . . . . . . 5 61 5.6. profile . . . . . . . . . . . . . . . . . . . . . . . . . 6 62 5.7. title . . . . . . . . . . . . . . . . . . . . . . . . . . 6 63 5.8. hreflang . . . . . . . . . . . . . . . . . . . . . . . . 6 64 6. Example Document . . . . . . . . . . . . . . . . . . . . . . 6 65 7. Media Type Parameters . . . . . . . . . . . . . . . . . . . . 7 66 7.1. profile . . . . . . . . . . . . . . . . . . . . . . . . . 7 67 8. Recommendations . . . . . . . . . . . . . . . . . . . . . . . 7 68 8.1. Self Link . . . . . . . . . . . . . . . . . . . . . . . . 7 69 8.2. Link relations . . . . . . . . . . . . . . . . . . . . . 7 70 8.3. Hypertext Cache Pattern . . . . . . . . . . . . . . . . . 8 71 9. Security Considerations . . . . . . . . . . . . . . . . . . . 9 72 10. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9 73 11. Normative References . . . . . . . . . . . . . . . . . . . . 9 74 Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 10 75 Appendix B. Frequently Asked Questions . . . . . . . . . . . . . 10 76 B.1. How should a client know the 77 meaning/structure/semantics/type of a resource? . . . . . 10 78 B.2. Where can I find libraries for working with HAL? . . . . 10 79 B.3. Why are the reserved properties prefixed with an 80 underscore? . . . . . . . . . . . . . . . . . . . . . . . 10 81 B.4. Are all underscore-prefixed properties reserved? . . . . 11 82 B.5. Why does HAL have no forms? . . . . . . . . . . . . . . . 11 83 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 11 85 1. Introduction 87 There is an emergence of non-HTML HTTP applications ("Web APIs") 88 which use hyperlinks to direct clients around their resources. 90 The JSON Hypertext Application Language (HAL) is a standard which 91 establishes conventions for expressing hypermedia controls, such as 92 links, with JSON [RFC4627]. 94 HAL is a generic media type with which Web APIs can be developed and 95 exposed as series of links. Clients of these APIs can select links 96 by their link relation type and traverse them in order to progress 97 through the application. 99 HAL's conventions result in a uniform interface for serving and 100 consuming hypermedia, enabling the creation of general-purpose 101 libraries that can be re-used on any API utilising HAL. 103 The primary design goals of HAL are generality and simplicity. HAL 104 can be applied to many different domains, and imposes the minimal 105 amount of structure necessary to cover the key requirements of a 106 hypermedia Web API. 108 2. Requirements 110 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 111 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 112 document are to be interpreted as described in [RFC2119]. 114 3. HAL Documents 116 A HAL Document uses the format described in [RFC4627] and has the 117 media type "application/hal+json". 119 Its root object MUST be a Resource Object. 121 For example: 123 GET /orders/523 HTTP/1.1 124 Host: example.org 125 Accept: application/hal+json 127 HTTP/1.1 200 OK 128 Content-Type: application/hal+json 130 { 131 "_links": { 132 "self": { "href": "/orders/523" }, 133 "warehouse": { "href": "/warehouse/56" }, 134 "invoice": { "href": "/invoices/873" } 135 }, 136 "currency": "USD", 137 "status": "shipped", 138 "total": 10.20 139 } 141 Here, we have a HAL document representing an order resource with the 142 URI "/orders/523". It has "warehouse" and "invoice" links, and its 143 own state in the form of "currency", "status", and "total" 144 properties. 146 4. Resource Objects 148 A Resource Object represents a resource. 150 It has two reserved properties: 152 (1) "_links": contains links to other resources. 154 (2) "_embedded": contains embedded resources. 156 All other properties MUST be valid JSON, and represent the current 157 state of the resource. 159 4.1. Reserved Properties 161 4.1.1. _links 163 The reserved "_links" property is OPTIONAL. 165 It is an object whose property names are link relation types (as 166 defined by [RFC5988]) and values are either a Link Object or an array 167 of Link Objects. The subject resource of these links is the Resource 168 Object of which the containing "_links" object is a property. 170 4.1.2. _embedded 172 The reserved "_embedded" property is OPTIONAL 174 It is an object whose property names are link relation types (as 175 defined by [RFC5988]) and values are either a Resource Object or an 176 array of Resource Objects. 178 Embedded Resources MAY be a full, partial, or inconsistent version of 179 the representation served from the target URI. 181 5. Link Objects 183 A Link Object represents a hyperlink from the containing resource to 184 a URI. It has the following properties: 186 5.1. href 188 The "href" property is REQUIRED. 190 Its value is either a URI [RFC3986] or a URI Template [RFC6570]. 192 If the value is a URI Template then the Link Object SHOULD have a 193 "templated" attribute whose value is true. 195 5.2. templated 197 The "templated" property is OPTIONAL. 199 Its value is boolean and SHOULD be true when the Link Object's "href" 200 property is a URI Template. 202 Its value SHOULD be considered false if it is undefined or any other 203 value than true. 205 5.3. type 207 The "type" property is OPTIONAL. 209 Its value is a string used as a hint to indicate the media type 210 expected when dereferencing the target resource. 212 5.4. deprecation 214 The "deprecation" property is OPTIONAL. 216 Its presence indicates that the link is to be deprecated (i.e. 217 removed) at a future date. Its value is a URL that SHOULD provide 218 further information about the deprecation. 220 A client SHOULD provide some notification (for example, by logging a 221 warning message) whenever it traverses over a link that has this 222 property. The notification SHOULD include the deprecation property's 223 value so that a client manitainer can easily find information about 224 the deprecation. 226 5.5. name 228 The "name" property is OPTIONAL. 230 Its value MAY be used as a secondary key for selecting Link Objects 231 which share the same relation type. 233 5.6. profile 235 The "profile" property is OPTIONAL. 237 Its value is a string which is a URI that hints about the profile (as 238 defined by [I-D.wilde-profile-link]) of the target resource. 240 5.7. title 242 The "title" property is OPTIONAL. 244 Its value is a string and is intended for labelling the link with a 245 human-readable identifier (as defined by [RFC5988]). 247 5.8. hreflang 249 The "hreflang" property is OPTIONAL. 251 Its value is a string and is intended for indicating the language of 252 the target resource (as defined by [RFC5988]). 254 6. Example Document 256 The following is an example document representing a list of orders 258 GET /orders HTTP/1.1 259 Host: example.org 260 Accept: application/hal+json 262 HTTP/1.1 200 OK 263 Content-Type: application/hal+json 265 { 266 "_links": { 267 "self": { "href": "/orders" }, 268 "next": { "href": "/orders?page=2" }, 269 "find": { "href": "/orders{?id}", "templated": true } 270 }, 271 "_embedded": { 272 "orders": [{ 273 "_links": { 274 "self": { "href": "/orders/123" }, 275 "basket": { "href": "/baskets/98712" }, 276 "customer": { "href": "/customers/7809" } 277 }, 278 "total": 30.00, 279 "currency": "USD", 280 "status": "shipped", 282 },{ 283 "_links": { 284 "self": { "href": "/orders/124" }, 285 "basket": { "href": "/baskets/97213" }, 286 "customer": { "href": "/customers/12369" } 287 }, 288 "total": 20.00, 289 "currency": "USD", 290 "status": "processing" 291 }] 292 }, 293 "currentlyProcessing": 14, 294 "shippedToday": 20 295 } 297 Here, the order list document provides a "next" link directing to the 298 next page, and a "find" link containing a URI Template which can be 299 expanded with an 'id' variable to go directly to a specific order. 301 It also has two embedded resources, "orders". Each of these has its 302 own links to the associated "basket" and "customer" resources, and 303 properties showing their "total", "currency" and "status". 305 Additionally, the order list resource has its own properties 306 "currentlyProcessing" and "shippedToday". 308 7. Media Type Parameters 310 7.1. profile 312 The media type identifier application/hal+json MAY also include an 313 additional "profile" parameter (as defined by 314 [I-D.wilde-profile-link]) 316 HAL documents that are served with the "profile" parameter still 317 SHOULD include a "profile" link belonging to the root resource. 319 8. Recommendations 321 8.1. Self Link 323 Each Resource Object SHOULD contain a 'self' link that corresponds 324 with the IANA registered 'self' relation (as defined by [RFC5988]) 325 whose target is the resource's URI. 327 8.2. Link relations 328 Custom link relation types (Extension Relation Types in [RFC5988]) 329 SHOULD be URIs that when dereferenced in a web browser provide 330 relevant documentation, in the form of an HTML page, about the 331 meaning and/or behaviour of the target Resource. This will improve 332 the discoverability of the API. 334 The CURIE Syntax [W3C.NOTE-curie-20101216] MAY be used for brevity 335 for these URIs. CURIEs are established within a HAL document via a 336 set of Link Objects with the relation type "curies" on the root 337 Resource Object. These links contain a URI Template with the token 338 'rel', and are named via the "name" property. 340 { 341 "_links": { 342 "self": { "href": "/orders" }, 343 "curies": [{ 344 "name": "acme", 345 "href": "http://docs.acme.com/relations/{rel}", 346 "templated": true 347 }], 348 "acme:widgets": { "href": "/widgets" } 349 } 350 } 352 The above demonstrates the relation "http://docs.acme.com/relations/ 353 widgets" being abbreviated to "acme:widgets" via CURIE syntax. 355 8.3. Hypertext Cache Pattern 357 The "hypertext cache pattern" allows servers to use embedded 358 resources to dynamically reduce the number of requests a client 359 makes, improving the efficiency and performance of the application. 361 Clients MAY be automated for this purpose so that, for any given link 362 relation, they will read from an embedded resource (if present) in 363 preference to traversing a link. 365 To activate this client behaviour for a given link, servers SHOULD 366 add an embedded resource into the representation with the same 367 relation. 369 Servers SHOULD NOT entirely "swap out" a link for an embedded 370 resource (or vice versa) because client support for this technique is 371 OPTIONAL. 373 The following examples shows the hypertext cache pattern applied to 374 an "author" link: 376 Before: 378 { 379 "_links": { 380 "self": { "href": "/books/the-way-of-zen" }, 381 "author": { "href": "/people/alan-watts" } 382 } 383 } 385 After: 387 { 388 "_links": { 389 "self": { "href": "/blog-post" }, 390 "author": { "href": "/people/alan-watts" } 391 }, 392 "_embedded": { 393 "author": { 394 "_links": { "self": { "href": "/people/alan-watts" } }, 395 "name": "Alan Watts", 396 "born": "January 6, 1915", 397 "died": "November 16, 1973" 398 } 399 } 400 } 402 9. Security Considerations 404 TBD 406 10. IANA Considerations 408 TBD 410 11. Normative References 412 [I-D.wilde-profile-link] 413 Wilde, E., "The 'profile' Link Relation Type", draft- 414 wilde-profile-link-04 (work in progress), October 2012. 416 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 417 Requirement Levels", BCP 14, RFC 2119, March 1997. 419 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 420 Resource Identifier (URI): Generic Syntax", STD 66, RFC 421 3986, January 2005. 423 [RFC4627] Crockford, D., "The application/json Media Type for 424 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 426 [RFC5988] Nottingham, M., "Web Linking", RFC 5988, October 2010. 428 [RFC6570] Gregorio, J., Fielding, R., Hadley, M., Nottingham, M., 429 and D. Orchard, "URI Template", RFC 6570, March 2012. 431 [W3C.NOTE-curie-20101216] 432 McCarron, S. and M. Birbeck, "CURIE Syntax 1.0", World 433 Wide Web Consortium NOTE NOTE-curie-20101216, December 434 2010, . 436 Appendix A. Acknowledgements 438 Thanks to Darrel Miller, Mike Amundsen, and everyone in hal-discuss 439 for their suggestions and feedback. 441 The author takes all responsibility for errors and omissions. 443 Appendix B. Frequently Asked Questions 445 B.1. How should a client know the meaning/structure/semantics/type of a 446 resource? 448 There are two main approaches to solving this problem. Both involve 449 exposing additional documentation describing the resource which may 450 be human and/or machine readable (i.e. an HTML page and/or a JSON 451 Schema document). The difference between the two approaches is in 452 where that URI is shared with the client, which is either: 454 (1) The URI that was the preceding link relation type. 456 (2) A 'profile' link from the resource itself. 458 B.2. Where can I find libraries for working with HAL? 460 A list of libraries is maintained here: http://stateless.co/ 461 hal_specification.html 463 B.3. Why are the reserved properties prefixed with an underscore? 464 We elected for a prefix character to minimise risk of collisions with 465 properties that represent the resource's state, and underscore was 466 the character picked. 468 Another reason for prefixing the reserved properties is to make it 469 visually apparent that the reserved properties are distinct from 470 standard properties belonging to the resource. 472 B.4. Are all underscore-prefixed properties reserved? 474 No, HAL only reserves the names detailed in this specification. 476 B.5. Why does HAL have no forms? 478 Omitting forms from HAL was an intentional design decision that was 479 made to keep it focused on linking for APIs. HAL is therefore a good 480 candidate for use as a base media type on which to build more complex 481 capabilities. An additional media type is planned for the future 482 which will add form-like controls on top of HAL. 484 Author's Address 486 Mike Kelly 487 Stateless 489 Email: mike@stateless.co 490 URI: http://stateless.co/