feat: refactor REST API

This commit is contained in:
2025-05-04 16:26:04 +02:00
parent bdd5f7bea5
commit d15ec1f8cb
8 changed files with 336 additions and 229 deletions

View File

@@ -25,13 +25,14 @@ All endpoints except `/health` require authentication via an API token passed in
| Method | Path | Description |
|--------|------|-------------|
| GET | `/health` | Health check endpoint that returns status |
| POST | `/network/up` | Create and activate a WiFi access point |
| POST | `/network/down` | Deactivate a WiFi interface |
| POST | `/network/remove` | Remove the stored connection profile |
| POST | `/network/ap` | Create and activate a WiFi access point |
| PUT | `/network/interface/{interface}` | Activate a connection |
| DELETE | `/network/interface/{interface}` | Deactivate a connection |
| DELETE | `/network/connection/{uuid}` | Remove a connection |
| GET | `/hostname` | Get the hostname |
| POST | `/hostname` | Set the hostname |
| POST | `/authorized-key` | Add an authorized SSH key |
| DELETE | `/authorized-key` | Remove an authorized SSH key |
| POST | `/users/{user}/keys` | Add an authorized SSH key |
| DELETE | `/users/{user}/keys/{fingerprint}` | Remove an authorized SSH key |
### Response Codes
@@ -42,79 +43,3 @@ All endpoints except `/health` require authentication via an API token passed in
### Request/Response Format
All endpoints use JSON for request and response payloads.
### Bring a network up
```bash
curl -v -X POST http://localhost:8080/network/up \
-H "Content-Type: application/json" \
-H "X-API-Token: 1234567890" \
-d '{
"interface": "wlan0",
"ssid": "MyNetworkSSID",
"password": "SuperSecretPassword"
}'
```
### Bring a network down
```bash
curl -v -X POST http://localhost:8080/network/down \
-H "Content-Type: application/json" \
-H "X-API-Token: 1234567890" \
-d '{
"interface": "wlan0"
}'
```
### Remove the stored connection
```bash
curl -v -X POST http://localhost:8080/network/remove \
-H "X-API-Token: 1234567890" \
-d '{
"interface": "wlan0"
}'
```
### Get the hostname
```bash
curl -v http://localhost:8080/hostname \
-H "X-API-Token: 1234567890"
```
### Set the hostname
```bash
curl -v -X POST http://localhost:8080/hostname \
-H "Content-Type: application/json" \
-H "X-API-Token: 1234567890" \
-d '{
"hostname": "MyHostname"
}'
```
### Add an authorized SSH key
```bash
curl -v -X POST http://localhost:8080/authorized-key \
-H "Content-Type: application/json" \
-H "X-API-Token: 1234567890" \
-d '{
"user": "pi",
"pubkey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC1234567890"
}'
```
### Remove an authorized SSH key
```bash
curl -v -X DELETE http://localhost:8080/authorized-key \
-H "Content-Type: application/json" \
-H "X-API-Token: 1234567890" \
-d '{
"user": "pi",
"pubkey": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC1234567890"
}'
```