- TypeScript 99.4%
- Dockerfile 0.6%
| config | ||
| database/migrations | ||
| docs/images | ||
| public | ||
| src | ||
| types/generated | ||
| .env.example | ||
| .gitignore | ||
| .prettierrc.json | ||
| favicon.png | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
Simple SpaceAPI
A simple SpaceAPI server with web and REST interfaces.
Built with Node.js using Strapi.
Quick Start
Install dependencies and start the server in development mode:
npm install
npm run develop
Most files are autogenerated.
The main entry point is ./src/api/spaceapi/controllers/spaceapi.ts.
Usage
All the data for your endpoint could be added and modified with the admin panel or with the REST API.
You could use the Strapi CLI to list all availible API endpoints:
npm run strapi routes:list
API Tokens
To update the data you need to obtain the API token.
You could define token's specific permissions in the admin panel.
For additional explanation see Strapi Tokens Documentation.
Examples
Some HTTPIe CLI requests here:
Main SpaceAPI Endpoint
http GET http://localhost:1337/api/spaceapi
Update the Hackspace State
API_TOKEN=your-token-here
http PUT \
http://localhost:1337/api/state \
Authorization:"Bearer $API_TOKEN" \
data:='{
"open": true,
"trigger_person": "Owner",
"message": "We are open!"
}'
Update the Sensors
API_TOKEN=your-token-here
# Discover the documentId for the sensor
http GET \
http://localhost:1337/api/temperature-sensors \
Authorization:"Bearer $API_TOKEN"
DOCUMENT_ID=nrfn2800pexpwxuhqikzr7xa
http PUT \
http://localhost:1337/api/temperature-sensors/$DOCUMENT_ID \
Authorization:"Bearer $API_TOKEN" \
data:='{
"unit": "°C",
"value": 25
}'
Caveats
Lastchange
Simple SpaceAPI not trying to be smart about timespamps so any successful update will affect this field.
For example if you set the hackspace state to "closed"
and repeat the same request next day
then lastchange will be overrided.
Validation
While Simple SpaceAPI is trying to validate the data it's still possible to generate invalid SpaceAPI JSON.
Do not forget to check your endpoint with the SpaceAPI Validator.
Units
Due to the some Strapi limitations several sensor units should be replaced with aliases for API requests:
- Humidity Sensor: use
percentsinstead of%; - Wind Sensor: use
degreeinstead of°;
Main SpaceAPI endpoint will show correct units.
Shape of Sensors
While Simple SpaceAPI is trying to follow the SpaceAPI structure, some sensors shape is simplified:
- Nested
alpha,beta,gammaandbeta_gammaradiation sensors were unified as genericradiation. Type of the sensor could be specified withtypefield.
Deployment
TBD
