Skip to content

Commit f9c8ca7

Browse files
committed
docs: reference/http/gateway/#api
Replaces placeholder with basic information about the API and points at follow-up resources (how-tos, specs)
1 parent 910ee05 commit f9c8ca7

File tree

4 files changed

+97
-19
lines changed

4 files changed

+97
-19
lines changed

docs/how-to/address-ipfs-on-web.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ For example, a website can load static assets from content-addressed paths:
5555
User agents that support IPFS, such as a browser with [ipfs-companion](https://docs.ipfs.io/install/ipfs-companion/), may recognize the `/ipfs/<CID>` content path and load the related asset over IPFS instead of HTTP. User agents without IPFS support still get the correct data from the original HTTP server.
5656
:::
5757

58-
### Path gateway
58+
## Path gateway
5959

6060
In the most basic scheme, a URL path used for content addressing is effectively a resource name without a canonical location. The HTTP server provides the location part, which makes it possible for browsers to interpret an IPFS content path as relative to the current server and just work without a need for any conversion:
6161

@@ -78,7 +78,7 @@ https://ipfs.io/ipfs/QmT5NvUtoM5nWFfrQdVrFtvGfKFmG7AHE8P34isapyhCxX/wiki/Mars.ht
7878
https://ipfs.io/ipns/tr.wikipedia-on-ipfs.org/wiki/Anasayfa.html
7979
```
8080

81-
### Subdomain gateway
81+
## Subdomain gateway
8282

8383
When [origin-based security](https://en.wikipedia.org/wiki/Same-origin_policy) is needed, [CIDv1](../concepts/content-addressing.md#identifier-formats) in case-insensitive encoding such as Base32 or Base36 should be used in the subdomain:
8484

@@ -157,7 +157,7 @@ $ ipfs cid format -v 1 -b base36 --codec libp2p-key QmNnooDu7bfjPFoTZYxMNLWUQJyr
157157
k2k4r8jl0yz8qjgqbmc2cdu5hkqek5rj6flgnlkyywynci20j0iuyfuj
158158
```
159159

160-
### DNSLink gateway
160+
## DNSLink gateway
161161

162162
The gateway provided by the IPFS daemon understands the `Host` header present in HTTP requests and will check if [DNSLink](../concepts/dnslink.md) exists for a specified [domain name](https://en.wikipedia.org/wiki/Fully_qualified_domain_name).
163163
If DNSLink is present, the gateway will return content from a path resolved via DNS TXT record.

docs/reference/http/gateway.md

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,112 @@ description: HTTP Gateway API reference for IPFS clients.
55

66
# HTTP Gateway reference
77

8-
Gateways provide implementation and runtime agnostic HTTP interface for retrieving [content-addressed](/concepts/glossary/#content-addressing) data from IPFS with regular HTTP clients and libraries.
8+
Gateways provide implementation and runtime agnostic HTTP interface for retrieving [content-addressed](../../concepts/glossary/#content-addressing) data from IPFS with regular HTTP clients and libraries.
99

10-
::: tip Before you dive into low level specifications...
1110

12-
Make sure you understand [how to address IPFS on the web](../how-to/address-ipfs-on-web/), and what are differences between [Path](/how-to/address-ipfs-on-web/#path-gateway) and [Subdomain Gateways](/how-to/address-ipfs-on-web/#subdomain-gateway).
11+
## API
12+
13+
### `GET /ipfs/{cid}[/{path}][?{params}]`
14+
15+
- `cid` is a [CID](https://docs.ipfs.io/concepts/glossary/#cid), the root identifier of the requested content path
16+
- `path` – optional path under the root CID
17+
18+
Optional query parameters:
19+
20+
- `filename` sets the name returned in `Content-Disposition` HTTP header
21+
- `download` set to `true` will skip rendering and force browsers to present a 'Save as' dialog
22+
- `format` URL-friendly alternative to sending `Accept` header
23+
24+
::: tip Before you continue
25+
26+
Make sure you understand [how to address IPFS on the web](../../how-to/address-ipfs-on-web/), and what are differences between [Path](../../how-to/address-ipfs-on-web/#path-gateway) and [Subdomain Gateways](../how-to/address-ipfs-on-web/#subdomain-gateway).
27+
28+
:::
29+
30+
## Trusted vs trustless
31+
32+
Gateways can be used in a trusted or trustless way.
33+
HTTP clients are in control, decide how much trust and work is delegated to the gateway.
34+
35+
### Delegating trust
36+
37+
By default, a gateway will take care of UnixFS deserialization and return reassembled files to the client, as if they were stored in a traditional HTTP server. This means all validation happens on the gateway, and clients trust the gateway is correctly validating content-addressed data before returning it to them.
38+
39+
#### Example: fetching an UnixFS file
40+
41+
```bash
42+
$ curl -L "https://ipfs.io/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi" > cat.jpg
43+
```
44+
45+
::: tip
46+
47+
When fetching a CID directly, one can include a `filename` parameter with file name to be used in `Content-Disposition` HTTP header: <https://ipfs.io/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?filename=cat.jpg>
48+
49+
:::
50+
51+
### Trustless, verifiable retrieval
52+
53+
Clients capable of verifying content-addressed data on their own, should use [application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw) and [application/vnd.ipld.car](https://www.iana.org/assignments/media-types/application/vnd.ipld.car) response types (raw [blocks](../concepts/glossary/#block) and [CARs](../concepts/glossary/#car)), and always ask for CIDs directly (`/ipfs/{cid}`).
54+
55+
#### Example: fetching a raw block
56+
57+
Using `Accept` HTTP header with [application/vnd.ipld.raw](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw) type:
58+
59+
```bash
60+
$ curl -L -H "Accept: application/vnd.ipld.raw" "https://ipfs.io/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi" > raw-block.bin
61+
$ ipfs block put raw-block.bin
62+
bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
63+
```
64+
65+
66+
::: tip
67+
68+
An alternative is to pass `?format=raw` URL parameter:
69+
70+
<https://ipfs.io/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?format=raw>
71+
1372
:::
1473

15-
::: warning SPECIFICATION (WORK IN PROGRESS)
74+
#### Example: fetching an entire DAG as a CAR stream
75+
76+
Using `Accept` HTTP header with [application/vnd.ipld.car](https://www.iana.org/assignments/media-types/application/vnd.ipld.car) type:
77+
78+
```bash
79+
$ curl -H "Accept: application/vnd.ipld.car" "https://ipfs.io/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi" > dag.car
80+
$ ipfs dag import dag.car
81+
```
82+
83+
::: tip
84+
85+
An alternative is to pass `?format=car` URL parameter:
86+
87+
<https://ipfs.io/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi?format=car>
88+
89+
:::
90+
91+
## Specifications
92+
93+
HTTP Gateway specification for IPFS implementers is available in [ipfs/specs](https://github.com/ipfs/specs/blob/main/http-gateways/#readme) repository.
94+
Below are links for the most useful specifications.
1695

17-
<!-- TODO update this section (at least the links) when ipfs/specs PR lands -->
18-
HTTP Gateway specification for IPFS implementers is available in [ipfs/specs](https://github.com/ipfs/specs/blob/main/http-gateways/#readme):
1996

2097
### HTTP
2198

2299
These are "low level" gateways that expose IPFS resources over HTTP protocol.
23100

24-
* [PATH_GATEWAY.md](https://github.com/ipfs/specs/blob/main/http-gateways/PATH_GATEWAY.md)**START HERE**
25-
* [TRUSTLESS_GATEWAY.md](https://github.com/ipfs/specs/blob/main/http-gateways/TRUSTLESS_GATEWAY.md)
101+
* [Path Gateway](https://github.com/ipfs/specs/blob/main/http-gateways/PATH_GATEWAY.md)**START HERE**, other types of gateway are specified as a delta against this specification.
102+
* [Trustless Gateway](https://github.com/ipfs/specs/blob/main/http-gateways/TRUSTLESS_GATEWAY.md) is a subset that returns verifiable response types (raw [blocks](../concepts/glossary/#block) and [CARs](../concepts/glossary/#car))
26103

27104
### Web
28105

29106
Special types of gateway which leverage `Host` header in addition to URL `pathname`. Designed for website hosting and improved interoperability with web browsers and [origin-based security model](https://en.wikipedia.org/wiki/Same-origin_policy).
30107

31-
* [SUBDOMAIN_GATEWAY.md](https://github.com/ipfs/specs/blob/main/http-gateways/SUBDOMAIN_GATEWAY.md)
32-
* [DNSLINK_GATEWAY.md](https://github.com/ipfs/specs/blob/main/http-gateways/DNSLINK_GATEWAY.md)
108+
* [Subdomain Gateway](https://github.com/ipfs/specs/blob/main/http-gateways/SUBDOMAIN_GATEWAY.md)
109+
* [DNSLink Website Hosting](https://github.com/ipfs/specs/blob/main/http-gateways/DNSLINK_GATEWAY.md)
110+
111+
::: tip
33112

34-
If you are a gateway operator or an implementer, consider providing feedback in [ipfs/specs](https://github.com/ipfs/specs/) repository.
113+
If you are a gateway operator or an implementer, consider joining [Gateway Operators Forum](https://discuss.ipfs.io/c/31)
35114

36115
:::
37116

38-
<!-- TODO document endpoints in brief and link to ipfs/specs for more details -->

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
"@vuepress/plugin-active-header-links": "^1.9.7",
1010
"@vuepress/plugin-back-to-top": "^1.9.7",
1111
"@vuepress/plugin-google-analytics": "^1.9.7",
12-
"@vuepress/plugin-html-redirect": "^0.1.2",
12+
"@vuepress/plugin-html-redirect": "^0.1.4",
1313
"@vuepress/plugin-last-updated": "^1.9.7",
1414
"husky": "^8.0.1",
1515
"lint-staged": "^13.0.3",
1616
"markdown-it-deflist": "^2.1.0",
17-
"markdown-it-footnote": "^3.0.2",
17+
"markdown-it-footnote": "^3.0.3",
1818
"markdown-it-image-lazy-loading": "^1.2.0",
1919
"markdown-it-imsize": "^2.0.1",
2020
"markdown-it-task-lists": "^2.1.1",

0 commit comments

Comments
 (0)