Skip to content

Commit c583e65

Browse files
committed
ipip: Streaming Routing V1 HTTP API
1 parent b07b1bc commit c583e65

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed

src/ipips/ipip-0410.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: "IPIP-0410: Streaming Routing V1 HTTP API"
3+
date: 2023-05-12
4+
ipip: proposal
5+
editors:
6+
- name: Henrique Dias
7+
github: hacdias
8+
url: https://hacdias.com/
9+
relatedIssues:
10+
- https://github.com/ipfs/specs/issues/344
11+
- https://github.com/ipfs/boxo/pull/18
12+
- https://github.com/ipfs/kubo/pull/9868
13+
- https://github.com/ipfs/kubo/pull/9874
14+
order: 410
15+
tags: ['ipips']
16+
---
17+
18+
Introduce backwards-compatible streaming support to the Routing V1 HTTP API.
19+
20+
Introduce backwards-compatible streaming support to the Routing V1 HTTP API by
21+
using the HTTP Header `Accept` (:cite[rfc9110]) with [Newline Delimited JSO (NDJSON)](http://ndjson.org/).
22+
23+
## Motivation
24+
25+
The main motivation for this change is that a server may take some time before fetching
26+
all the peers they know providing a certain CID. That will add some latency when sending
27+
a non-streamed response, as they need to wait for the whole discovery period.
28+
29+
With streaming support, the server is able to respond with a *read provider record*
30+
as they themselves discover the peers, not needing to wait for the whole discovery
31+
to return the provider records.
32+
33+
## Detailed design
34+
35+
In summary, streaming is supported by using the `Accept` HTTP header (:cite[rfc9110])
36+
along with the `application/x-ndjson` content type. For more details regarding the design,
37+
check :cite[http-routing-v1].
38+
39+
## Design rationale
40+
41+
The idea is to not break compatibility with existing clients and servers. Therefore,
42+
we can use the `Accept` HTTP header for content negotiation. If the client supports
43+
streaming, they can advertise so by including `application/x-ndjson` in the headers.
44+
If the server supports streaming, the response will have `Content-Type` HTTP header
45+
of `application/x-ndjson` with a streaming response. Otherwise, it will fall back
46+
to a pure JSON, non-streamed, response.
47+
48+
### User benefit
49+
50+
Users (clients) will benefit from this change as the servers will now be able
51+
to respond more promptly to provider record requests. Instead of waiting for the whole
52+
list to be constructed, servers can now return each provider record one by one,
53+
in a streaming fashion.
54+
55+
### Compatibility
56+
57+
The introduced changes are backwards-compatible. The introduced header is completely
58+
optional, and a server that does not support streaming is able to respond with a non-streaming
59+
response to the client. Equally, non-streaming responses are the default. Therefore, a
60+
client that does not support streaming will not receive a streamed response.
61+
62+
### Security
63+
64+
Security considerations are equivalent as the ones in :cite[ipip-0337].
65+
66+
### Copyright
67+
68+
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

src/routing/http-routing-v1.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ date: 2023-03-22
88
maturity: reliable
99
editors:
1010
- name: Gus Eggert
11-
github: guseggert
11+
github: guseggert
12+
- name: Henrique Dias
13+
url: https://hacdias.com/
14+
github: hacdias
1215
order: 0
1316
tags: ['routing']
1417
---
@@ -67,7 +70,7 @@ Specifications for some transfer protocols are provided in the "Transfer Protoco
6770

6871
### `GET /routing/v1/providers/{CID}`
6972

70-
#### Response codes
73+
#### Response Codes
7174

7275
- `200` (OK): the response body contains 0 or more records
7376
- `404` (Not Found): must be returned if no matching records are found
@@ -97,7 +100,23 @@ This API does not support pagination, but optional pagination can be added in a
97100

98101
## Streaming
99102

100-
This API does not currently support streaming, however it can be added in the future through a backwards-compatible update by using a content type other than `application/json`.
103+
This API supports streaming requests made by sending an `Accept` HTTP Header containing
104+
`application/x-ndjson`. The response will be formatted as [Newline Delimited JSON (ndjson)](http://ndjson.org/),
105+
with one *read provider record* per line:
106+
107+
108+
```json
109+
{"Protocol": "<protocol_name>", "Schema": "<schema>", ...}
110+
{"Protocol": "<protocol_name>", "Schema": "<schema>", ...}
111+
{"Protocol": "<protocol_name>", "Schema": "<schema>", ...}
112+
...
113+
```
114+
115+
Streaming is backwards-compatible with clients that do not support streaming. Please note the following:
116+
117+
- Requests without an `Accept` header MUST default to regular, non-streaming, responses.
118+
- The server MAY respond with non-streaming response even if the client requests streaming.
119+
- The server MUST NOT respond with streaming response if the client did not request so.
101120

102121
## Error Codes
103122

0 commit comments

Comments
 (0)