Skip to content

Commit 61186f0

Browse files
committed
chore(ipip-410): final editorials
1 parent 36571b0 commit 61186f0

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/ipips/ipip-0410.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "IPIP-0410: Streaming Routing V1 HTTP API"
2+
title: "IPIP-0410: Streaming NDJSON in Routing HTTP API"
33
date: 2023-05-12
44
ipip: proposal
55
editors:
@@ -15,6 +15,8 @@ order: 410
1515
tags: ['ipips']
1616
---
1717

18+
## Summary
19+
1820
Introduce backwards-compatible streaming support to the Routing V1 HTTP API.
1921
For this, we use the `Accept` HTTP header (:cite[rfc9110]) for content type negotiation, as well
2022
as the Newline Delimited JSON ([NDJSON]) format.
@@ -27,6 +29,9 @@ the client requests a list of providers for a CID from the server. Then, the cli
2729
has to wait for the server to collect their final list of providers. After that,
2830
the server can respond with the full list of providers.
2931

32+
This is a big source of latency when `/routing/v1` is used for delegating DHT lookups,
33+
where the client is forced to wait for the server to finish DHT walk.
34+
3035
With streaming support, the server is able to respond with provider records as soon
3136
as they are available. This reduces latency and allows for faster content discovery.
3237

@@ -65,6 +70,13 @@ to respond more promptly to provider record requests. Instead of waiting for the
6570
list to be constructed, servers can now return each provider record one by one,
6671
in a streaming fashion.
6772

73+
The client will be able to close connection at any time, reducing load on both ends.
74+
75+
The main use cases for this IPIP are light clients and services which want to
76+
delegate DHT lookups to external service. With streaming, clients will be able
77+
to receive results as soon the delegated service learns about new record, which
78+
directly impacts the content load speeds perceived by the end user.
79+
6880
### Compatibility
6981

7082
The introduced changes are backwards-compatible. The introduced header is completely

src/routing/http-routing-v1.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ order: 0
2020
tags: ['routing']
2121
---
2222

23-
Delegated routing is a mechanism for IPFS implementations to use for offloading content routing and naming to another process/server. This specification describes an HTTP API for delegated content routing.
23+
Delegated routing is a mechanism for IPFS implementations to use for offloading content routing and naming to another process/server. This specification describes a vendor-agnostic HTTP API for delegated content routing.
2424

2525
## API Specification
2626

@@ -142,23 +142,34 @@ This API does not support pagination, but optional pagination can be added in a
142142

143143
## Streaming
144144

145-
JSON-based endpoints support streaming requests made by sending an `Accept` HTTP Header containing
146-
`application/x-ndjson`. The response will be formatted as [Newline Delimited JSON (ndjson)](https://github.com/ndjson/ndjson-spec),
147-
with one *read provider record* per line:
145+
JSON-based endpoints support streaming requests made
146+
with `Accept: application/x-ndjson` HTTP Header.
148147

148+
Steaming responses are formatted as
149+
[Newline Delimited JSON (ndjson)](https://github.com/ndjson/ndjson-spec),
150+
with one result per line:
149151

150152
```json
151-
{"Protocol": "<protocol_name>", "Schema": "<schema>", ...}
152-
{"Protocol": "<protocol_name>", "Schema": "<schema>", ...}
153-
{"Protocol": "<protocol_name>", "Schema": "<schema>", ...}
153+
{"Schema": "<schema>", ...}
154+
{"Schema": "<schema>", ...}
155+
{"Schema": "<schema>", ...}
154156
...
155157
```
156158

157-
Streaming is backwards-compatible with clients that do not support streaming. Please note the following:
159+
:::note
158160

159-
- Requests without an `Accept` header MUST default to regular, non-streaming, responses.
160-
- The server MAY respond with non-streaming response even if the client requests streaming.
161-
- The server MUST NOT respond with streaming response if the client did not request so.
161+
Streaming is opt-in and backwards-compatibile with clients and servers that do
162+
not support streaming:
163+
164+
- Requests without the `Accept: application/x-ndjson` header MUST default to
165+
regular, non-streaming, JSON responses.
166+
- Legacy server MAY respond with non-streaming `application/json` response even
167+
if the client requested streaming. It is up to the client to inspect
168+
the `Content-Type` header before parsing the response.
169+
- The server MUST NOT respond with streaming response if the client did not
170+
explicitly request so.
171+
172+
:::
162173

163174
## Error Codes
164175

0 commit comments

Comments
 (0)