Delegated Routing V1 HTTP API (original) (raw)

IPFS Standards

29 October 2024

status: reliable

History

Commit History

Feedback

GitHub ipfs/specs (inspect source, open issue)

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

Table of Contents

  1. 1. API Specification
  2. 2. Common Data Types
  3. 3. Versioning
  4. 4. Content Routing API
    1. 4.1 GET /routing/v1/providers/{cid}
      1. 4.1.1 Path Parameters
      2. 4.1.2 Request Query Parameters
        1. 4.1.2.1 filter-addrs (providers request query parameter)
        2. 4.1.2.2 filter-protocols (providers request query parameter)
      3. 4.1.3 Response Status Codes
      4. 4.1.4 Response Headers
      5. 4.1.5 Response Body
  5. 5. Peer Routing API
    1. 5.1 GET /routing/v1/peers/{peer-id}
      1. 5.1.1 Path Parameters
      2. 5.1.2 Request Query Parameters
        1. 5.1.2.1 filter-addrs (peers request query parameter)
        2. 5.1.2.2 filter-protocols (peers request query parameter)
      3. 5.1.3 Response Status Codes
      4. 5.1.4 Response Headers
      5. 5.1.5 Response Body
  6. 6. IPNS API
    1. 6.1 GET /routing/v1/ipns/{name}
      1. 6.1.1 Path Parameters
      2. 6.1.2 Response Status Codes
      3. 6.1.3 Response Headers
      4. 6.1.4 Response Body
    2. 6.2 PUT /routing/v1/ipns/{name}
      1. 6.2.1 Path Parameters
      2. 6.2.2 Request Body
      3. 6.2.3 Response Status Codes
  7. 7. Pagination
  8. 8. Streaming
  9. 9. Error Codes
  10. 10. CORS and Web Browsers
  11. 11. Known Schemas
  12. 11.1 Peer Schema
  13. 11.2 Legacy Schemas
    1. 11.2.1 Bitswap Schema
    2. 11.2.2 Graphsync Schema
  14. A. References
  15. B. Acknowledgments

1. API Specification

The Routing HTTP API uses the application/json content type by default. For IPNS Names, the verifiable application/vnd.ipfs.ipns-record content type is used.

As such, human-readable encodings of types are preferred. This specification may be updated in the future with a compact application/cbor encoding, in which case compact encodings of the various types would be used.

2. Common Data Types

Until required for business logic, servers should treat these types as opaque strings, and should preserve unknown JSON fields.

3. Versioning

This API uses a standard version prefix in the path, such as /v1/.... If a backwards-incompatible change must be made, then the version number should be increased.

4. Content Routing API

4.1 GET /routing/v1/providers/{cid}

4.1.1 Path Parameters

4.1.2 Request Query Parameters

4.1.2.1 filter-addrs (providers request query parameter)

Optional ?filter-addrs to apply Network Address Filtering from IPIP-484.

4.1.2.2 filter-protocols (providers request query parameter)

Optional ?filter-protocols to apply IPFS Protocol Filtering from IPIP-484.

4.1.3 Response Status Codes

4.1.5 Response Body

{
  "Providers": [
    {
      "Schema": "<schema>",
      "ID": "bafz...",
      "Addrs": ["/ip4/..."],
      ...
    },
    ...
  ]
}

The application/json responses SHOULD be limited to 100 providers.

The client SHOULD be able to make a request with Accept: application/x-ndjson and get a stream with more results.

Each object in the Providers list is a record conforming to a schema, usually the Peer Schema.

5. Peer Routing API

5.1 GET /routing/v1/peers/{peer-id}

5.1.1 Path Parameters

5.1.2 Request Query Parameters

5.1.2.1 filter-addrs (peers request query parameter)

Optional, same rules as filter-addrs providers request query parameter.

5.1.2.2 filter-protocols (peers request query parameter)

Optional, same rules as filter-protocols providers request query parameter.

5.1.3 Response Status Codes

5.1.5 Response Body

{
  "Peers": [
    {
      "Schema": "<schema>",
      "Protocols": ["<protocol-a>", "<protocol-b>", ...],
      "ID": "bafz...",
      "Addrs": ["/ip4/..."],
      ...
    },
    ...
  ]
}

The application/json responses SHOULD be limited to 100 peers.

The client SHOULD be able to make a request with Accept: application/x-ndjson and get a stream with more results.

Each object in the Peers list is a record conforming to the Peer Schema.

6. IPNS API

6.1 GET /routing/v1/ipns/{name}

6.1.1 Path Parameters

6.1.2 Response Status Codes

6.1.4 Response Body

The response body contains a IPNS Record serialized using the verifiable application/vnd.ipfs.ipns-record protobuf format.

6.2 PUT /routing/v1/ipns/{name}

6.2.1 Path Parameters

6.2.2 Request Body

The content body must be a application/vnd.ipfs.ipns-record serialized IPNS Record, with a valid signature matching the name path parameter.

6.2.3 Response Status Codes

8. Streaming

JSON-based endpoints support streaming requests made with Accept: application/x-ndjson HTTP Header.

Steaming responses are formatted asNewline Delimited JSON (ndjson), with one result per line:

{"Schema": "<schema>", ...}
{"Schema": "<schema>", ...}
{"Schema": "<schema>", ...}
...

Streaming is opt-in and backwards-compatible with clients and servers that do not support streaming:

9. Error Codes

10. CORS and Web Browsers

Browser interoperability requires implementations to supportCORS.

JavaScript client running on a third-party Origin must be able to send HTTP request to the endpoints defined in this specification, and read the received values. This means HTTP server implementing this API must (1) supportCORS preflight requestssent as HTTP OPTIONS, and (2) always respond with headers that remove CORS limits, allowing every site to query the API for results:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, OPTIONS

11. Known Schemas

This section contains a non-exhaustive list of known schemas that MAY be supported by clients and servers.

11.1 Peer Schema

The peer schema represents an arbitrary peer.

{
  "Schema": "peer",
  "ID": "bafz...",
  "Addrs": ["/ip4/..."],
  "Protocols": ["transport-bitswap", ...]
  ...
}

To allow for protocol-specific fields and future-proofing, the parser _MUST_allow for unknown fields, and the clients MUST ignore unknown ones.

Below is an example on how one could include protocol-a and protocol-bprotocols that includes an additional fields protocol-a and protocol-b.

If the client knows the protocol, they are free to use the extra binary (base64) or JSON information contained in the additional field. If that is not the case, the field MUST be ignored.

{
  "Schema": "peer",
  "ID": "bafz...",
  "Addrs": ["/ip4/..."],
  "Protocols": ["transport-bitswap", "protocol-a", "protocol-b", ...],
  "protocol-a": "[base64-blob]",
  "protocol-b": { "foo": "bar" }
}

11.2 Legacy Schemas

Legacy schemas include ID and optional Addrs list just like the peer schema does.

These schemas are deprecated and SHOULD be replaced with peer over time, but_MAY_ be returned by some legacy endpoints. In such case, a client MAY parse them the same way as the peer schema.

11.2.1 Bitswap Schema

A legacy schema used by some routers to indicate a peer supports retrieval over the /ipfs/bitswap[/*] libp2p protocol.

{
  "Protocol": "transport-bitswap",
  "Schema": "bitswap",
  "ID": "bafz...",
  "Addrs": ["/ip4/..."]
}

11.2.2 Graphsync Schema

A legacy schema used by some routers to indicate a peer supports retrieval over the graphsynclibp2p protocol.

{
  "Protocol": "transport-graphsync-filecoinv1",
  "Schema": "graphsync-filecoinv1",
  "ID": "bafz...",
  "Addrs": ["/ip4/..."],
  "PieceCID": "<cid>",
  "VerifiedDeal": true,
  "FastRetrieval": true
}

A. References

[rfc2119]

Key words for use in RFCs to Indicate Requirement Levels. S. Bradner. IETF. March 1997. Best Current Practice. URL: https://www.rfc-editor.org/rfc/rfc2119

B. Acknowledgments

We gratefully acknowledge the following individuals for their valuable contributions, ranging from minor suggestions to major insights, which have shaped and improved this specification.

Editors

Gus Eggert (Protocol Labs) GitHub

Masih H. Derkani (Protocol Labs) GitHub

Henrique Dias (Shipyard) GitHub

Marcin Rataj (Shipyard) GitHub

Daniel Norman (Shipyard) GitHub