Git Product home page Git Product logo

ipfs-rest-api's Introduction

Introduction

This project allows users to upload files to the InterPlanetary File System (IPFS). JSON web tokens (JWT) are supported for the add and delete endpoints. Unit tests are included for the REST layer; consult the section below for instructions.

Activating the project

1st Method
  1. In the root folder, enter docker-compose up. This will run a Flask API container and an IPFS daemon container.
2nd Method
  1. Create a new python virtual environment.
  2. Enter the rest folder, and install environment with pip install -r requirements.txt.
  3. Start the flask API layer with python run.py.
  4. Start the IPFS daemon with ipfs daemon.

Sample curl commands

Postman JSON commands can be found at IPFS Collections.postman_collection in the main directory

// Register a new user, receive access token
curl -X POST \
  http://0.0.0.0:8081/registration \
  -H 'Content-Type: application/json' \
  -d '{
    "username": "bob",
    "password": "hill"
}'

// Upload a file - Requires JWT access_token
curl -X POST \
  http://0.0.0.0:8081/add \
  -H 'Cache-Control: no-cache' \
  -H 'content-type: multipart/form-data; 
  -H "Authorization: JWT <token here>"
  -F fileObj=File to upload

// Delete a file - Requires JWT access_token
curl -X POST \
  http://0.0.0.0:8081/delete \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -H "Authorization: JWT <token here>"
  -d '{
	"file": "Content Base Address"
}'

Unit Tests

There are unit tests for most endpoints in the rest folder. Begin testing with python test.py. Note that ipfs daemon must be running to test the add and delete endpoints.

Repo Organization

The REST api is created with flask framework. the key files are:

app.py

  • creates a flask app set up with REST endpoints
  • includes an SQLite database based on the ORM model described in models

models.py

  • creates an object relational model (ORM) for handling user information
  • declares token black list model

resources.py

  • stores the implementation details of each endpoint.

run.py

  • main entry point for the app

Other Notes

You can ensure that a file has been uploaded correctly by running ipfs cat content_base__address > result.png.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.