You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Avoiding sending the same response messages twice](#avoiding-sending-the-same-response-messages-twice)
27
+
-[Client controls for time-based caching](#client-controls-for-time-based-caching)
28
+
-[Rate-limiting non-cachable POST requests](#rate-limiting-non-cachable-post-requests)
26
29
-[Implementations](#implementations)
27
30
28
-
# HTTP Transport Design
31
+
## HTTP Endpoint
32
+
33
+
```
34
+
https://rpc-service.example.net/reframe
35
+
```
36
+
37
+
URL of a Reframe endpoint must end with `/reframe` path.
38
+
39
+
### Content type
40
+
41
+
Requests SHOULD be sent with explicit `Accept` and `Content-Type` HTTP headers specifying the body format.
42
+
43
+
All messages sent in HTTP body MUST be encoded as either:
44
+
-[DAG-CBOR](https://ipld.io/specs/codecs/dag-cbor/spec/), and use explicit content type `application/vnd.ipfs.rpc+dag-cbor; version=1`
45
+
-**This is a CBOR (binary) format for use in production.**
46
+
- CBOR request MUST include HTTP header: `Accept: application/vnd.ipfs.rpc+dag-cbor; version=1`
47
+
- CBOR request AND response MUST include header: `Content-Type: application/vnd.ipfs.rpc+dag-cbor; version=1`
48
+
-[DAG-JSON](https://ipld.io/specs/codecs/dag-json/spec/), and use explicit content type `application/vnd.ipfs.rpc+dag-json; version=1`
49
+
-**This is a human-readable plain text format for use in testing and debugging.**
50
+
- JSON request MUST include header: `Accept: application/vnd.ipfs.rpc+dag-json; version=1`
51
+
- JSON request AND response MUST include header: `Content-Type: application/vnd.ipfs.rpc+dag-json; version=1`
52
+
53
+
54
+
Implementations SHOULD error when an explicit content type is missing, but MAY decide to implement some defaults instead.
55
+
The rules around implicit content type are as follows:
56
+
- Requests without a matching `Content-Type` header MAY be interpreted as DAG-JSON.
57
+
- Requests without a matching `Accept` header MAY produce a DAG-JSON response.
58
+
- Responses without a matching `Content-Type` header MAY be interpreted as DAG-JSON.
29
59
30
-
All messages sent in HTTP body MUST be encoded as DAG-JSON and use explicit content type `application/vnd.ipfs.rpc+dag-json; version=1`
60
+
### HTTP methods
31
61
32
62
Requests MUST be sent as either:
63
+
-`GET /reframe/{mbase64url-dag-cbor}`
64
+
- Cachable HTTP `GET` requests with message passed as DAG-CBOR in HTTP path segment, encoded as URL-safe [`base64url` multibase](https://docs.ipfs.io/concepts/glossary/#base64url) string
65
+
- DAG-CBOR in multibase `base64url` is used (even when request body is DAG-JSON) because JSON may include characters that are not safe to be used in URLs, and percent-encoding or base-encoding a big JSON query may take too much space.
66
+
- Suitable for sharing links, sending bigger messages, and when a query result MUST benefit from HTTP caching (see _HTTP Caching Considerations_ below).
33
67
-`GET /reframe?q={percent-encoded-dag-json}`
34
68
- DAG-JSON is supported via a `?q` query parameter, and the value MUST be [percent-encoded](https://en.wikipedia.org/wiki/Percent-encoding)
35
69
- Suitable for sharing links, sending smaller messages, testing and debugging.
36
70
-`POST /reframe`
37
-
- Ephemeral HTTP `POST` request with message passed as DAG-JSON in HTTP request body
71
+
- Ephemeral HTTP `POST` request with DAG-JSON or DAG-CBOR message passed in HTTP request body
38
72
- Suitable for bigger messages, and when HTTP caching should be skipped for the most fresh results
39
73
40
74
Servers MUST support `GET` for methods marked as cachable and MUST support `POST` for all methods (both cachable and not-cachable). This allows servers to rate-limit `POST` when cachable `GET` could be used instead, and enables clients to use `POST` as a fallback in case there is a technical problem with bigger Reframe messages not fitting in a `GET` URL. See "Caching Considerations" section.
41
75
76
+
### Other notes
42
77
43
78
If a server supports HTTP/1.1, then it MAY send chunked-encoded messages. Clients supporting HTTP/1.1 MUST accept chunked-encoded responses.
44
79
45
80
Requests and Responses MUST occur over a single HTTP call instead of the server being allowed to dial back the client with a response at a later time. The response status code MUST be 200 if the RPC transaction succeeds, even when there's an error at the application layer, and a non-200 status code if the RPC transaction fails.
46
81
47
-
If a server chooses to respond to a single request message with a group of messages in the response it should do so as a set of `\n` delimited DAG-JSON messages (i.e. `{Response1}\n{Response2}...`).
82
+
If a server chooses to respond to a single request message with a group of DAG-JSON messages in the response it should do so as a set of `\n` delimited DAG-JSON messages (i.e. `{Response1}\n{Response2}...`).
83
+
DAG-CBOR responses require no special handling, as they are already self-delimiting due to the nature of the CBOR encoding.
48
84
49
85
Requests and responses MUST come with `version=1` as a _Required Parameter_ in the `Accept` and `Content-Type` HTTP headers.
50
86
@@ -99,6 +135,6 @@ too many POST requests: consider switching to cachable GET or try again later (s
0 commit comments