Skip to content

Commit b51edda

Browse files
committed
Clarify how baseurl and absolute/relative URLs interact
This is driven by DOMjudge/domjudge#2378 where DOMjudge had issues shadowing PC^2 because PC^2 returned absolute URLs in the file href attribute, while these should have been relative URLs (without a `/` prefix). Also note that if a baseurl does not end with a `/`, then according to https://www.ietf.org/rfc/rfc2119.txt, the last path component must be removed when constructing a final URL with a relative URL.
1 parent 763735a commit b51edda

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Contest_API.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ The specific base URL of this API will be dependent on the server (e.g.
4848
main CCS or CDS) providing the service; in the specification we only
4949
indicate the relative paths of API endpoints with respect to a
5050
**baseurl**. In all the examples below the baseurl is
51-
<https://example.com/api>.
51+
<https://example.com/api/>.
52+
53+
The baseurl must end in a slash so that relative URLs are resolved
54+
correctly. If `baseurl` is <https://example.com/api/foobar>, then
55+
per [RFC 3986](https://tools.ietf.org/html/rfc3986) the relative URL
56+
`contests/wf14` resolves to `https://example.com/api/contests/wf14`,
57+
*just* as it would with `baseurl` set to <https://example.com/api/>.
5258

5359
We follow standard REST practices so that a whole collection can be
5460
requested, e.g. at the URL path
@@ -268,12 +274,13 @@ Properties for file reference objects:
268274
The `href` property may be an [absolute or relative
269275
URL](https://tools.ietf.org/html/rfc3986); relative URLs must be
270276
interpreted relative to the `baseurl` of the API. For example, if
271-
`baseurl` is <https://example.com/api>, then the following are
277+
`baseurl` is <https://example.com/api/>, then the following are
272278
equivalent JSON response snippets pointing to the same location:
273279

274280
```json
275281
"href":"https://example.com/api/contests/wf14/submissions/187/files"
276282
"href":"contests/wf14/submissions/187/files"
283+
"href":"/api/contests/wf14/submissions/187/files"
277284
```
278285

279286
For images, the supported mime types are image/png, image/jpeg, and image/svg+xml.
@@ -1664,7 +1671,7 @@ Returned data:
16641671

16651672
Note that the relative link for `files` points to the location
16661673
<https://example.com/api/contests/wf14/submissions/187/files> since the
1667-
base URL for the API is <https://example.com/api>.
1674+
base URL for the API is <https://example.com/api/>.
16681675

16691676
Request:
16701677

0 commit comments

Comments
 (0)