176
176
<postamble >
177
177
If the instance is {"id": 1234}, and its base URI according to
178
178
<xref target =" RFC3986" >RFC 3986 section 5.1</xref >, is
179
- "https://api. example.com/", then "https://api. example.com/thing/1234"
179
+ "https://example.com/api/ ", then "https://example.com/api /thing/1234"
180
180
is the resulting link's target URI.
181
181
</postamble >
182
182
</figure >
@@ -1551,14 +1551,14 @@ for varname in templateData:
1551
1551
<section title =" Entry Point Links, No Templates" anchor =" entryPoint" >
1552
1552
<t >
1553
1553
For this example, we will assume an example API with a documented
1554
- entry point URI of https://api. example.com, which is an empty JSON object
1554
+ entry point URI of https://example.com/api , which is an empty JSON object
1555
1555
with a link to a schema. Here, the entry point has no data of its
1556
1556
own and exists only to provide an initial set of links:
1557
1557
</t >
1558
1558
<figure >
1559
1559
<artwork >
1560
1560
<![CDATA[
1561
- GET https://api. example.com HTTP/1.1
1561
+ GET https://example.com/api HTTP/1.1
1562
1562
1563
1563
200 OK
1564
1564
Content-Type: application/json
@@ -1570,23 +1570,22 @@ Link: <https://schema.example.com/entry>; rel="describedBy"
1570
1570
<t >
1571
1571
The linked hyper-schema defines the API's base URI and provides
1572
1572
two links: an "about" link to API documentation, and a "self"
1573
- link indicating that this is a schema for the base URI. In this
1574
- case the base URI is also the entry point URI.
1573
+ link indicating that this is a schema for the base URI.
1575
1574
</t >
1576
1575
<figure >
1577
1576
<artwork >
1578
1577
<![CDATA[
1579
1578
{
1580
1579
"$id": "https://schema.example.com/entry",
1581
1580
"$schema": "http://json-schema.org/draft-08/hyper-schema#",
1582
- "base": "https://api. example.com/",
1581
+ "base": "https://example.com/api /",
1583
1582
"links": [
1584
1583
{
1585
1584
"rel": "self",
1586
- "href": ""
1585
+ "href": "../api",
1587
1586
}, {
1588
1587
"rel": "about",
1589
- "href": "/ docs"
1588
+ "href": "docs"
1590
1589
}
1591
1590
]
1592
1591
}]]>
@@ -1596,21 +1595,41 @@ Link: <https://schema.example.com/entry>; rel="describedBy"
1596
1595
These are the simplest possible links, with only a relation type and
1597
1596
an "href" with no template variables. They resolve as follows:
1598
1597
</t >
1598
+ <t >
1599
+ The duplication of "api" in both the base and the "../api"
1600
+ href in the "self" link is due to quirks of the RFC 3986
1601
+ URI-reference resolution algorithm. In order for relative
1602
+ URI-references to work well in general, the base URI needs
1603
+ to include a trailing slash. The "about" link with its "docs"
1604
+ href shows the common case of relative references, which is
1605
+ used in the other examples in this document.
1606
+ </t >
1607
+ <t >
1608
+ However, if an API uses URIs without trailing slashes for its resources,
1609
+ there is no way to provide a relative reference that just removes a
1610
+ trailing slash without duplicating the path component above it.
1611
+ Which makes the case of the entry point resource, which differs
1612
+ from the base URI only in terms of the trailing slash, somewhat awkward.
1613
+ </t >
1614
+ <t >
1615
+ Resource URIs, of course, may have trailing slashes, but this example
1616
+ is intended to highlight this frequently confusing special case.
1617
+ </t >
1599
1618
<figure >
1600
1619
<artwork >
1601
1620
<![CDATA[ [
1602
1621
{
1603
- "contextUri": "https://api. example.com",
1622
+ "contextUri": "https://example.com/api ",
1604
1623
"contextPointer": "",
1605
1624
"rel": "self",
1606
- "targetUri": "https://api. example.com",
1625
+ "targetUri": "https://example.com/api ",
1607
1626
"attachmentPointer": ""
1608
1627
},
1609
1628
{
1610
- "contextUri": "https://api. example.com",
1629
+ "contextUri": "https://example.com/api ",
1611
1630
"contextPointer": "",
1612
1631
"rel": "about",
1613
- "targetUri": "https://api. example.com/docs",
1632
+ "targetUri": "https://example.com/api /docs",
1614
1633
"attachmentPointer": ""
1615
1634
}
1616
1635
]]]>
@@ -1633,7 +1652,7 @@ Link: <https://schema.example.com/entry>; rel="describedBy"
1633
1652
<![CDATA[ {
1634
1653
"$id": "https://schema.example.com/thing",
1635
1654
"$schema": "http://json-schema.org/draft-08/hyper-schema#",
1636
- "base": "https://api. example.com/",
1655
+ "base": "https://example.com/api /",
1637
1656
"type": "object",
1638
1657
"required": ["data"],
1639
1658
"properties": {
@@ -1830,7 +1849,7 @@ Link: <https://schema.example.com/entry>; rel="describedBy"
1830
1849
</list >
1831
1850
</t >
1832
1851
<t >
1833
- So, given the following instance retrieved from "https://api. example.com/stuff":
1852
+ So, given the following instance retrieved from "https://example.com/api /stuff":
1834
1853
</t >
1835
1854
<figure >
1836
1855
<artwork >
@@ -1848,7 +1867,7 @@ Link: <https://schema.example.com/entry>; rel="describedBy"
1848
1867
<figure >
1849
1868
<artwork >
1850
1869
<![CDATA[ {
1851
- "contextUri": "https://api. example.com/stuff",
1870
+ "contextUri": "https://example.com/api /stuff",
1852
1871
"contextPointer": "",
1853
1872
"rel": "author",
1854
1873
"hrefInputTemplates": [
@@ -1902,14 +1921,14 @@ Link: <https://schema.example.com/entry>; rel="describedBy"
1902
1921
</preamble >
1903
1922
<artwork >
1904
1923
<![CDATA[
1905
- GET https://api. example.com/trees/1/nodes/123 HTTP/1.1
1924
+ GET https://example.com/api /trees/1/nodes/123 HTTP/1.1
1906
1925
1907
1926
200 OK
1908
1927
Content-Type: application/json
1909
- Link: <https://api. example.com/trees/1/nodes/123>; rel="self"
1910
- Link: <https://api. example.com/trees/1/nodes/123>; rel="up";
1911
- anchor="https://api. example.com/trees/1/nodes/456"
1912
- Link: <https://api. example.com/trees/1/nodes/456>; rev="up"
1928
+ Link: <https://example.com/api /trees/1/nodes/123>; rel="self"
1929
+ Link: <https://example.com/api /trees/1/nodes/123>; rel="up";
1930
+ anchor="https://example.com/api /trees/1/nodes/456"
1931
+ Link: <https://example.com/api /trees/1/nodes/456>; rev="up"
1913
1932
{
1914
1933
"id": 123,
1915
1934
"treeId": 1,
@@ -1998,7 +2017,7 @@ Link: <https://api.example.com/trees/1/nodes/456>; rev="up"
1998
2017
<![CDATA[ {
1999
2018
"$id": "https://schema.example.com/thing",
2000
2019
"$schema": "http://json-schema.org/draft-08/hyper-schema#",
2001
- "base": "https://api. example.com/",
2020
+ "base": "https://example.com/api /",
2002
2021
"type": "object",
2003
2022
"required": ["data"],
2004
2023
"properties": {
@@ -2051,7 +2070,7 @@ Link: <https://api.example.com/trees/1/nodes/456>; rev="up"
2051
2070
<![CDATA[ {
2052
2071
"$id": "https://schema.example.com/thing-collection",
2053
2072
"$schema": "http://json-schema.org/draft-08/hyper-schema#",
2054
- "base": "https://api. example.com/",
2073
+ "base": "https://example.com/api /",
2055
2074
"type": "object",
2056
2075
"required": ["elements"],
2057
2076
"properties": {
@@ -2104,52 +2123,52 @@ Link: <https://api.example.com/trees/1/nodes/456>; rev="up"
2104
2123
<artwork >
2105
2124
<![CDATA[ [
2106
2125
{
2107
- "contextUri": "https://api. example.com/things",
2126
+ "contextUri": "https://example.com/api /things",
2108
2127
"contextPointer": "",
2109
2128
"rel": "self",
2110
- "targetUri": "https://api. example.com/things",
2129
+ "targetUri": "https://example.com/api /things",
2111
2130
"attachmentPointer": ""
2112
2131
},
2113
2132
{
2114
- "contextUri": "https://api. example.com/things",
2133
+ "contextUri": "https://example.com/api /things",
2115
2134
"contextPointer": "/elements/0",
2116
2135
"rel": "self",
2117
- "targetUri": "https://api. example.com/things/12345",
2136
+ "targetUri": "https://example.com/api /things/12345",
2118
2137
"attachmentPointer": "/elements/0"
2119
2138
},
2120
2139
{
2121
- "contextUri": "https://api. example.com/things",
2140
+ "contextUri": "https://example.com/api /things",
2122
2141
"contextPointer": "/elements/1",
2123
2142
"rel": "self",
2124
- "targetUri": "https://api. example.com/things/67890",
2143
+ "targetUri": "https://example.com/api /things/67890",
2125
2144
"attachmentPointer": "/elements/1"
2126
2145
},
2127
2146
{
2128
- "contextUri": "https://api. example.com/things",
2147
+ "contextUri": "https://example.com/api /things",
2129
2148
"contextPointer": "",
2130
2149
"rel": "item",
2131
- "targetUri": "https://api. example.com/things/12345",
2150
+ "targetUri": "https://example.com/api /things/12345",
2132
2151
"attachmentPointer": "/elements/0"
2133
2152
},
2134
2153
{
2135
- "contextUri": "https://api. example.com/things",
2154
+ "contextUri": "https://example.com/api /things",
2136
2155
"contextPointer": "",
2137
2156
"rel": "item",
2138
- "targetUri": "https://api. example.com/things/67890",
2157
+ "targetUri": "https://example.com/api /things/67890",
2139
2158
"attachmentPointer": "/elements/1"
2140
2159
},
2141
2160
{
2142
- "contextUri": "https://api. example.com/things",
2161
+ "contextUri": "https://example.com/api /things",
2143
2162
"contextPointer": "/elements/0",
2144
2163
"rel": "collection",
2145
- "targetUri": "https://api. example.com/things",
2164
+ "targetUri": "https://example.com/api /things",
2146
2165
"attachmentPointer": "/elements/0"
2147
2166
},
2148
2167
{
2149
- "contextUri": "https://api. example.com/things",
2168
+ "contextUri": "https://example.com/api /things",
2150
2169
"contextPointer": "/elements/1",
2151
2170
"rel": "collection",
2152
- "targetUri": "https://api. example.com/things",
2171
+ "targetUri": "https://example.com/api /things",
2153
2172
"attachmentPointer": "/elements/1"
2154
2173
}
2155
2174
]]]>
@@ -2310,19 +2329,19 @@ Link: <https://api.example.com/trees/1/nodes/456>; rev="up"
2310
2329
<artwork >
2311
2330
<![CDATA[ [
2312
2331
{
2313
- "contextUri": "https://api. example.com/things",
2332
+ "contextUri": "https://example.com/api /things",
2314
2333
"contextPointer": "",
2315
2334
"rel": "self",
2316
2335
"targetUri":
2317
- "https://api. example.com/things?offset=0&limit=2",
2336
+ "https://example.com/api /things?offset=0&limit=2",
2318
2337
"attachmentPointer": ""
2319
2338
},
2320
2339
{
2321
- "contextUri": "https://api. example.com/things",
2340
+ "contextUri": "https://example.com/api /things",
2322
2341
"contextPointer": "",
2323
2342
"rel": "next",
2324
2343
"targetUri":
2325
- "https://api. example.com/things?offset=3&limit=2",
2344
+ "https://example.com/api /things?offset=3&limit=2",
2326
2345
"attachmentPointer": ""
2327
2346
}
2328
2347
]]]>
0 commit comments