Giter Site home page Giter Site logo

subrelay-api's Introduction

Subrelay API

This is the API server for the Subrelay project. It handles all API requests and provides data to the front-end.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • Node.js
  • NPM
  • Redis
  • Postgres

Installing

  1. Clone the repository
$ git clone https://github.com/subrelay/subrelay-api.git
  1. Navigate to the project directory
$ cd subrelay-api
  1. Rename .env.dist to .env and update values in that file

  2. Install the dependencies

$ npm install
  1. Start the server
$ npm start

Migration

Generate new migration

npm run typeorm migration:generate ./src/migration/{your_migration_name}

Run migration

npm run typeorm migration:run

Revert migration

npm run typeorm migration:revert

Self-hosting

Docker is required.

Installing SubRelay API

Clone the repository

Build Event Service to a docker image

Running command:

cd event-service
docker build -t subrelay-event-service .

Start the server

Database and Redis environment variables in Event Service and Subrelay API are the same.

Running command:

cd subrelay-api
docker-compose up -d --build

Go to http://localhost:3000/ to check.

API Reference

For more details on the API, check the API documentation.

Authentication

Request header

{
  "Authorization": "Your toke here"
}

How to generate a token?

import { stringToU8a, u8aToHex } from '@polkadot/util';

const message = JSON.stringify({ endpoint, method, body, timestamp });
const signature = sign(stringToHex(messsage));
const token = JSON.stringify({ address, timestamp, signature }).toString('base64');

GET token

GET token is used for GET endpoints. Where the endpoint, method, and body values are fixed. You need to sign it once and use it for all GET endpoints until it expires.

For example:

{
    "endpoint": "/*",
    "method": "GET",
    "body": {},
    "timestamp": 1669702265438
}

ACTION token

ACTION token is used for POST, PUT, DELETE endpoints. Where the endpoint, method, and body values are depend on each request.

For example:

{
    "endpoint": "/workflows",
    "method": "POST",
    "body": {
        "name": "workflow 2",
        "chainUuid": "9f294e84-0a4e-497b-95dc-785c06c1a2f0",
        "tasks": []
    },
    "timestamp": 1669702265438
}

How long token is expired ?

Authentication token expiration is 1 day.

How admin can access the API?

If you want to access the API as an admin, you must:

  • Define your account address when setup API.
  • Using GET token to access the API.

subrelay-api's People

Contributors

chi-bes avatar budtr avatar chidtr avatar

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.