A TypeScript API for managing IoT relay devices. Each IoT relay device connects to the MQTT broker and then becomes available for receiving and sending commands to the broker
The project starts the following containers:
- Node.js: for the TypeScript API
- Postgres: for the database
- Adminer: for the graphical management of the database
- MQTT: for MQTT communication
$ git clone https://github.com/knaiskes/RelayCentral-api.git
There is a file called .env_example as a starting point. Based on it, create a new file called .env and change the variables based on your perferences.
$ cp .env_example .env
Generate TOKEN_SECRET and TOKEN_SECRET_REFRESH tokens with Node
$ node
> require('crypto').randomBytes(64).toString('hex'); // Run it twice and use the
result for your tokens variables
$ cd RelayCentral-api/
$ docker-compose up --build
The base URL is: localhost:3001/api/v1
Endpoint | Description | HTTP Method |
---|---|---|
/relays | Get all the relays | GET |
/relays/{id} | Get a single relay by id | GET |
/relays | Post a new relay | POST |
/relays/{id} | Patch a specific relay | PATCH |
/relays/{id} | Delete a relay | DELETE |
This example assumes that you already created a user.
$ curl -X POST -H 'Content-Type: application/json' -d '{"username": "user", "password": "password"}' localhost:3001/api/v1/get-token
$ curl -H "Authorization:token" http://localhost:3001/api/v1/relays
$ curl -X POST -H 'Content-Type: application/json' -d '{"refreshToken": "refresh-token"}' localhost:3001/api/v1/refresh-token