|
| 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/). |
0 commit comments