Skip to content
Fission's core web services: registration, validation, file pinning, &c
Haskell Makefile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update Pull Request Template (#190) Nov 8, 2019
app
assets Shrink logo (#31) Jun 12, 2019
benchmark README & tests (#2) May 3, 2019
doctest
example-config Rename awsMock to route53Mock (#230) Dec 16, 2019
library Make `Fission.Internal.Meta` reusable downstream (#258) Feb 13, 2020
lint
sql Fix 500 on heroku deprovision (#246) Jan 9, 2020
test JWT Public Key Auth (via higher order auth) (#228) Feb 12, 2020
.codeclimate.yml
.ghci Initial Makefile (#173) Oct 25, 2019
.gitignore
.hlint.yaml Configure TravisCI (#37) Jun 18, 2019
.stylish-haskell.yaml Initial webapp setup Apr 30, 2019
.travis.yml Effectful HSpecs (#253) Feb 4, 2020
LICENSE
Makefile Effectful HSpecs (#253) Feb 4, 2020
README.md
Setup.hs Initial webapp setup Apr 30, 2019
package.yaml
stack.yaml Update dependencies (#256) Feb 12, 2020
stack.yaml.lock Autoversioning Swagger Docs (#257) Feb 12, 2020

README.md

FISSION IPFS Web API

Build Status License Built by FISSION Discord Discourse

A library and application to help Web 2.0-style applications leverage IPFS in a familiar, compatible way

Note: The cli has been broken out into it's own repo

QuickStart

Install dependencies

# IPFS on MacOS, otherwise https://docs.ipfs.io/introduction/install/
brew install ipfs
brew services start ipfs

# If using Linux, install libpq-dev
# sudo apt install libpq-dev

Setup config

# Enable sample Heroku config
# Note: You will have to edit this file to input dummy data
cp example-config/addon-manifest.json.example addon-manifest.json

# Setup env file
cp example-config/env.yaml.example env.yaml

Run Server

# Dev Web Server
export DEBUG=true
stack run

Setup your database

# Create the database
createdb web_api

# Apply the projects database schema
stack repl
λ> import Fission.Internal.Development as Development (pgConnectInfo)
λ> import Fission.Storage.PostgreSQL.Migrate
λ> sequence_ $ mutations Development.pgConnectInfo

Get your FISSION credentials

note: you will need to fill out your addon-manifest properly to acquire the appropriate credentials

curl -u "APP_MANIFEST_ID:APP_MANIFEST_PASSWORD" \
     -H "Content-Type: application/json" \
     -H "Accept: application/vnd.heroku-addons+json; version=3" \
     -X POST http://localhost:1337/heroku/resources/ \
     -d '{
           "name"         : "my-awesome-app",
           "uuid"         : "01234567-89ab-cdef-0123-456789abcdef",
           "plan"         : "free",
           "callback_url" : "http://foo.bar.quux",
           "region"       : "amazon-web-services::ap-northeast-1"
         }' | json_pp

Send your first request

curl \
  -H "Content-Type: text/plain;charset=utf-8" \
  -u "FISSION_USERNAME:FISSION_PASSWORD" \
  -d "hello world" \
  http://localhost:1337/ipfs

Development

There is a Makefile filled with helpful commands. The most used in development is make dev.

# Install development tools
make setup

# Watch project for changes, validating types and syntax
make dev

# Run the server and live reload
make live

Configuration

Environment Variables

Environment variables are set via the command line (e.g. export PORT=80)

PORT

Default: 1337

The port to run the web server on.

TLS

Default: false

Run the server with TLS enabled.

NB: PORT needs to be set separately.

DEBUG

Default: false

Log with colours and more output. Prefixed by RIO_ to make it compatible with SimpleApp.

PRETTY_REQS

Default: false

Log HTTP requests in easy-to-read multiline format

DB_PATH

Default: web-api.sqlite

Path to the SQLite databse

IPFS_PATH

Default: /usr/local/bin/ipfs

Path to the local IPFS binary

MONITOR

Default: false

Live monitoring dashboard

export MONITOR=true
stack run
open http://localhost:9630

Load Test

A very simple local load test:

# HTTP1.1
ab -n 10000 -c 100 http://localhost:1337/ping/

# HTTP2
brew install nghttp2
h2load -n10000 -c100 -t2 http://localhost:1337/ping/

Manual Workflow

curl -H "Authorization: Basic 012345generatedfrommanifest==" \
     -H "Content-Type: application/json" \
     -H "Accept: application/vnd.heroku-addons+json; version=3" \
     -X POST http://localhost:1337/heroku/resources/ \
     -d '{
           "name"         : "my-awesome-app",
           "uuid"         : "01234567-89ab-cdef-0123-456789abcdef",
           "plan"         : "free",
           "callback_url" : "http://foo.bar.quux",
           "region"       : "amazon-web-services::ap-northeast-1"
         }' | json_pp

#   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#                                  Dload  Upload   Total   Spent    Left  Speed
# 100   563    0   372  100   191  20871  10716 --:--:-- --:--:-- --:--:-- 21882
# {
#    "message" : "Successfully provisioned Interplanetary FISSION!",
#    "id"      : 5,
#    "config"  : {
#       "INTERPLANETARY_FISSION_USERNAME" : "c74bd95b8555275277d4",
#       "INTERPLANETARY_FISSION_PASSWORD" : "GW0SHByPmY0.y+lg)x7De.PNmJvh1",
#       "INTERPLANETARY_FISSION_URL"      : "localhost:1337"
#    }
# }

Encode basic auth from INTERPLANETARY_FISSION_USERNAME:INTERPLANETARY_FISSION_PASSWORD -- curl using the -u USER:PASS will encode and add the header for you automatically:

curl -i \
     -X POST \
     -H "Content-Type: application/octet-stream" \
     -u 'USER:PASS' \
     -d '{"hi":1}' \
     http://localhost:1337/ipfs

# HTTP/1.1 200 OK
# Transfer-Encoding: chunked
# Date: XXXXXXXXXXXXXXXXXXXXXXXX
# Server: Warp/3.2.27
# Content-Type: text/plain;charset=utf-8
#
# QmSeDGD18CLeUyKrATcaCbmH4Z3gyh3SrdgjoYkrxkEmgx

MIME Types

Valid Types

  • application/octet-stream
  • text/plain; charset=UTF-8
  • multipart/form-data

Defaults

  • Content-Type
    • Must be specified (no default)
    • Typically want application/octet-stream
  • Accept: text/plain;charset=utf-8
  • NB: When requesting text/plain, the character set must be specified

Example

Using the --data-binary and a /path/to/file can upload binary file types.

curl -i \
    -X POST \
    -u 'USER:PASS' \
    -H "Content-Type: application/octet-stream" # This line
    --data-binary @/path/to/file \
    http://localhost:1337/ipfs

# HTTP/1.1 200 OK
# Transfer-Encoding: chunked
# Date: XXXXXXXXXXXXXXXXXXXX
# Server: Warp/3.2.27
# Content-Type: text/plain;charset=utf-8
#
# QmSeDGD18CLeUyKrATcaCbmH4Z3gyh3SrdgjoYkrxkEmgx

Note that all of these examples will work with our public api at hostless.dev/ipfs. You will need a username and password from our Heroku Add-on.

You can’t perform that action at this time.