This is the API server for the Subrelay project. It handles all API requests and provides data to the front-end.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Node.js
- NPM
- Redis
- Postgres
- Clone the repository
$ git clone https://github.com/subrelay/subrelay-api.git
- Navigate to the project directory
$ cd subrelay-api
-
Rename
.env.dist
to.env
and update values in that file -
Install the dependencies
$ npm install
- Start the server
$ npm start
npm run typeorm migration:generate ./src/migration/{your_migration_name}
npm run typeorm migration:run
npm run typeorm migration:revert
Docker is required.
Running command:
cd event-service
docker build -t subrelay-event-service .
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.
For more details on the API, check the API documentation.
{
"Authorization": "Your toke here"
}
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 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 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
}
Authentication token expiration is 1 day.
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.