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.
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.
0x72
) codec.Until required for business logic, servers should treat these types as opaque strings, and should preserve unknown JSON fields.
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.
GET /routing/v1/providers/{cid}
cid
is the CID to fetch provider records for.200
(OK): the response body contains 0 or more records.404
(Not Found): must be returned if no matching records are found.422
(Unprocessable Entity): request does not conform to schema or semantic constraints.{
"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.
GET /routing/v1/peers/{peer-id}
peer-id
is the Peer ID to fetch peer records for,
represented as a CIDv1 encoded with libp2p-key
codec.200
(OK): the response body contains the peer record.404
(Not Found): must be returned if no matching records are found.422
(Unprocessable Entity): request does not conform to schema or semantic constraints.{
"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.
GET /routing/v1/ipns/{name}
name
is the IPNS Name to resolve, encoded as CIDv1.200
(OK): the response body contains the IPNS Record for the given IPNS Name.404
(Not Found): must be returned if no matching records are found.406
(Not Acceptable): requested content type is missing or not supported. Error message returned in body should inform the user to retry with Accept: application/vnd.ipfs.ipns-record
.Etag
: a globally unique opaque string used for HTTP caching. MUST be derived from the protobuf record returned in the body.Cache-Control: max-age={TTL}
: cache TTL returned with IPNS Record that has IpnsEntry.data[TTL] > 0
. When present, SHOULD match the TTL value from the record. When record was not found (HTTP 404) or has no TTL (value is 0
), implementation SHOULD default to max-age=60
.The response body contains a IPNS Record serialized using the verifiable application/vnd.ipfs.ipns-record
protobuf format.
PUT /routing/v1/ipns/{name}
name
is the IPNS Name to publish, encoded as CIDv1.The content body must be a application/vnd.ipfs.ipns-record
serialized IPNS Record, with a valid signature matching the name
path parameter.
200
(OK): the provided IPNS Record was published.400
(Bad Request): the provided IPNS Record or IPNS Name are not valid.406
(Not Acceptable): submitted content type is not supported. Error message returned in body should inform the user to retry with Content-Type: application/vnd.ipfs.ipns-record
.This API does not support pagination, but optional pagination can be added in a backwards-compatible spec update.
JSON-based endpoints support streaming requests made
with Accept: application/x-ndjson
HTTP Header.
Steaming responses are formatted as Newline 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:
Accept: application/x-ndjson
header MUST default to
regular, non-streaming, JSON responses.application/json
response even
if the client requested streaming. It is up to the client to inspect
the Content-Type
header before parsing the response.400
(Bad Request): must be returned if an unknown path is requested.429
(Too Many Requests): may be returned along with optional Retry-After header to indicate to the caller that it is issuing requests too quickly.501
(Not Implemented): must be returned if a method/path is not supported.Browser interoperability requires implementations to support CORS.
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) support CORS preflight requests sent 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
This section contains a non-exhaustive list of known schemas that MAY be supported by clients and servers.
The peer
schema represents an arbitrary peer.
{
"Schema": "peer",
"ID": "bafz...",
"Addrs": ["/ip4/..."],
"Protocols": ["transport-bitswap", ...]
...
}
ID
: the Peer ID as Multihash in Base58btc or CIDv1 with libp2p-key codec.Addrs
: an optional list of known multiaddrs for this peer.
ID
to lookup updated peer information.Protocols
: an optional list of protocols known to be supported by this peer.
ID
and Addrs
to lookup connect to the peer and use the libp2p identify protocol to learn about supported ones.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-b
protocols 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" }
}
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.
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/..."]
}
A legacy schema used by some routers to indicate a peer supports retrieval over the graphsync libp2p protocol.
{
"Protocol": "transport-graphsync-filecoinv1",
"Schema": "graphsync-filecoinv1",
"ID": "bafz...",
"Addrs": ["/ip4/..."],
"PieceCID": "<cid>",
"VerifiedDeal": true,
"FastRetrieval": true
}