Get your own NeoFS HTTP Gateway

Obtain

The gateway lives on GitHub and you can grab the latest release in a standard way (single binary). However, if you prefer dockerized setup, we have this option covered as well with Docker Hub.

Run

HTTP gateway is exactly that — just a gateway between HTTP and NeoFS protocol; so it relies on NeoFS nodes for data access. It means that you need to provide it with NeoFS node address that will be used for request processing. This can be done either via -p parameter or via HTTP_GW_PEERS_<N>_ADDRESS and HTTP_GW_PEERS_<N>_WEIGHT environment variables. The gateway also supports specifying multiple NeoFS nodes with weighted load balancing, which can be used for more complex setups.

$ neofs-http-gw -p 192.168.130.72:8080
$ HTTP_GW_PEERS_0_ADDRESS=192.168.130.72:8080 neofs-http-gw

Access

To get an object via HTTP, you can use /get/$CID/$OID path where $CID is a container ID and $OID is an object ID. If your cat is stored as 2m8PtaoricLouCn5zE8hAFr3gZEBDCZFe9BEgVJTSocY in Dxhf4PNprrJHWWTG5RGLdfLkJiSQ3AQqit1MSnEPRkDZ you can obtain it as following

$ wget http://localhost:8082/get/Dxhf4PNprrJHWWTG5RGLdfLkJiSQ3AQqit1MSnEPRkDZ/2m8PtaoricLouCn5zE8hAFr3gZEBDCZFe9BEgVJTSocY
$ wget http://localhost:8082/get_by_attribute/Dxhf4PNprrJHWWTG5RGLdfLkJiSQ3AQqit1MSnEPRkDZ/FileName/cat.jpeg
$ wget http://localhost:8082/get_by_attribute/Dxhf4PNprrJHWWTG5RGLdfLkJiSQ3AQqit1MSnEPRkDZ/Ololo/100500

Wrap

location  ~ "^/[0-9a-zA-Z]{43,44}/[0-9a-zA-Z\-]{43,44}$" {
rewrite /(.*) /get/$1 break;
proxy_pass http://127.0.0.1:8082;
proxy_cache neofs_cache;
proxy_cache_methods GET;
}
location / {
rewrite '/([0-9a-zA-Z]{43,44})/(.*)' /get_by_attribute/$1/FileName/$2 break;
proxy_pass http://127.0.0.1:8082;
proxy_cache neofs_cache;
proxy_cache_methods GET;
}
location ~ "^/[0-9a-zA-Z]{43,44}/$" {
rewrite '/([0-9a-zA-Z]{43,44})/' /get_by_attribute/$1/FileName/index.html break;
proxy_pass <http://127.0.0.1:8082;>
proxy_cache neofs_cache;
proxy_cache_methods GET;
}

Upload

NeoFS HTTP Protocol Gateway is not just for downloading things from NeoFS, you can also put new objects via /upload/$CID URL where $CID is a container ID. FileName attribute is set automatically in this case based on uploaded file name, but you can also manually add as many attributes as you like:

$ curl -F 'file=@cat.jpeg;filename=cat.jpeg' -H "X-Attribute-Ololo: 100500" http://localhost:8082/upload/Dxhf4PNprrJHWWTG5RGLdfLkJiSQ3AQqit1MSnEPRkDZ

Have fun

So, NeoFS HTTP Protocol Gateway allows you to host your dApp data on NeoFS and access it from frontend and backend via standard HTTP. In future, we plan to launch a truly distributed CDN working with NeoFS gateways, so that there will be even more functional options for NeoFS integration with existing ecosystem.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store