2.4 KiB
SpaceAPI Server
A Flask-based server implementation of the SpaceAPI specification, designed to provide real-time status information about a hackerspace. This server allows you to expose your space's status through a standardized API endpoint and update it using a secure token-based authentication system.
Features
- Compliant with SpaceAPI v14 and v15 specifications
- Secure token-based authentication for state updates
- Docker support for easy deployment
- Real-time space status updates
- Configurable space information (name, location, contact details, etc.)
- Production-ready with Gunicorn WSGI server
Prerequisites
- Docker (for containerized deployment)
- Python 3.11+ (for local development)
Environment Variables
The following environment variables need to be set:
SPACEAPI_TOKEN
: A secret token used to authenticate state update requestsFLASK_APP
: Set toapp.py
(automatically set in Docker)FLASK_ENV
: Set toproduction
(automatically set in Docker)
Deployment with Docker
-
Clone the repository:
git clone <repository-url> cd spaceapi-server
-
Create a
.env
file with your configuration:cp .env.example .env # Edit .env and set your SPACEAPI_TOKEN
-
Build and run the Docker container:
docker build -t spaceapi-server . docker run -p 5000:5000 --env-file .env spaceapi-server
The server will be available at http://localhost:5000
.
API Endpoints
GET /
Returns the current space status in SpaceAPI format.
POST /state
Updates the space status. Requires authentication using the X-SpaceAPI-Token
header.
Example request:
curl -X POST http://localhost:5000/state \
-H "Content-Type: application/json" \
-H "X-SpaceAPI-Token: your-token-here" \
-d '{"open": true}'
Local Development
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables and run the server:
# For development (using Flask's development server) export SPACEAPI_TOKEN=your-token-here flask run # For production-like environment (using Gunicorn) export SPACEAPI_TOKEN=your-token-here gunicorn --bind 0.0.0.0:5000 --workers 4 app:app
License
[Add your license information here]