GatherHub provides a comprehensive RESTful API for programmatic control over the application. This enables automation, integration with other systems, and building custom interfaces.
The API server is configured in the config.toml
file:
[api]
enabled = true
host = '127.0.0.1'
port = 5000
debug = false
[api.auth]
enabled = true
api_secret = 'your-api-key'
apiKey_expiry_hours = 24
To disable authentication for development or trusted environments, set api.auth.enabled
to false
.
secret
.
To start the API server, use the --api
flag:
./gatherhub --api
You can also run the API server alongside other components:
./gatherhub --api --web --daemon
When authentication is enabled, all API requests require a API Key in the Authorization header:
GET /api/jobs
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
The authentication implementation uses simple API Key validation based on the configured secret key. The token is required for all endpoints when authentication is enabled.
The following endpoints are defined in the API server (internal/api/server.go
). These endpoints provide the
essential functionality of GatherHub's API.
Endpoint | Method | Description |
---|---|---|
/api/jobs |
GET | Get all jobs (up to 1000) |
/api/jobs |
POST | Add a new job |
/api/jobs/{id} |
GET | Get job by ID |
/api/jobs/{id} |
PUT | Update job status and error message |
/api/jobs/{id} |
DELETE | Delete job |
GET /api/jobs
Response (array of job objects):
[
{
"id": 1,
"source_id": "bookmark123",
"source_name": "firefox-bookmarks",
"url": "https://example.com",
"media_type": "html",
"status": "completed",
"file_path": {"String": "./downloads/html/example_com_1.html", "Valid": true},
"created_at": "2023-05-10T14:00:00Z",
"updated_at": "2023-05-10T14:05:20Z",
"attempts": 1,
"error": {"String": "", "Valid": false}
},
...
]
POST /api/jobs
Content-Type: application/json
{
"url": "https://github.com/username/repository",
"source_name": "manual",
"source_id": "user_123",
"media_type": "git"
}
Response (created job object):
{
"id": 42,
"source_id": "user_123",
"source_name": "manual",
"url": "https://github.com/username/repository",
"media_type": "git",
"status": "pending",
"created_at": "2023-05-10T15:00:00Z",
"updated_at": "2023-05-10T15:00:00Z",
"attempts": 0,
"error": {"String": "", "Valid": false}
}
GET /api/jobs/42
Response (job object):
{
"id": 42,
"source_id": "user_123",
"source_name": "manual",
"url": "https://github.com/username/repository",
"media_type": "git",
"status": "completed",
"file_path": {"String": "./downloads/git/repository_42", "Valid": true},
"created_at": "2023-05-10T15:00:00Z",
"updated_at": "2023-05-10T15:05:30Z",
"attempts": 1,
"error": {"String": "", "Valid": false}
}
PUT /api/jobs/42
Content-Type: application/json
{
"status": "failed",
"error": "Connection timeout"
}
Response (updated job object):
{
"id": 42,
"source_id": "user_123",
"source_name": "manual",
"url": "https://github.com/username/repository",
"media_type": "git",
"status": "failed",
"file_path": {"String": "", "Valid": false},
"created_at": "2023-05-10T15:00:00Z",
"updated_at": "2023-05-10T15:10:00Z",
"attempts": 1,
"error": {"String": "Connection timeout", "Valid": true}
}
DELETE /api/jobs/42
Response: HTTP 204 No Content
Endpoint | Method | Description |
---|---|---|
/api/bulk/jobs |
POST | Perform operations on multiple jobs |
POST /api/bulk/jobs
Content-Type: application/json
{
"action": "delete",
"ids": [1, 2, 3, 4]
}
Response:
{
"success": true,
"deleted": 3,
"failed": 1,
"message": "Deleted 3 jobs, 1 failed"
}
The action
field can be one of:
delete
- Delete multiple jobsretry
- Retry multiple jobs (set status to "pending")Endpoint | Method | Description |
---|---|---|
/api/scan |
POST | Scan sources for new content |
/api/download |
POST | Process pending downloads |
/api/retry |
POST | Retry failed downloads |
/api/clean |
POST | Clean failed and old jobs |
/api/stats |
GET | Get system statistics |
POST /api/scan
Response: HTTP 200 OK
Scan completed
POST /api/download
Response: HTTP 200 OK
Download processing completed
POST /api/retry
Response: HTTP 200 OK
Retry completed
POST /api/clean
Response: HTTP 200 OK
Cleaned 5 failed jobs and 10 old jobs
GET /api/stats
Response:
{
"status_counts": {
"pending": 5,
"downloading": 2,
"completed": 120,
"failed": 8
},
"media_type_counts": {
"html": 80,
"videos": 30,
"git": 15,
"images": 10
},
"total_count": 135
}
Endpoint | Method | Description |
---|---|---|
/api/upload |
POST | Upload files directly |
POST /api/upload
Content-Type: multipart/form-data
file: [file data]
media_type: pdf (optional)
Response:
{
"success": true,
"message": "2 of 2 files uploaded successfully",
"jobs": [
{
"id": 157,
"url": "file:///path/to/uploaded/file1.pdf",
"source_name": "Manual Upload",
"source_id": "upload",
"media_type": "pdf",
"status": "completed"
},
{
"id": 158,
"url": "file:///path/to/uploaded/file2.jpg",
"source_name": "Manual Upload",
"source_id": "upload",
"media_type": "jpg",
"status": "completed"
}
],
"job": {
"id": 157,
"url": "file:///path/to/uploaded/file1.pdf",
"source_name": "Manual Upload",
"source_id": "upload",
"media_type": "pdf",
"status": "completed"
}
}
The API returns appropriate HTTP status codes:
200 OK
- Successful request204 No Content
- Successful deletion400 Bad Request
- Invalid request parameters401 Unauthorized
- Authentication required404 Not Found
- Resource not found405 Method Not Allowed
- Invalid HTTP method500 Internal Server Error
- Server-side errorError responses include a message:
Failed to decode job: unexpected EOF
To scan for new content and then download it:
# Scan sources
curl -X POST http://localhost:5000/api/scan
# Process pending downloads
curl -X POST http://localhost:5000/api/download
# Add a new job
curl -X POST http://localhost:5000/api/jobs \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "media_type": "html"}'
# Get all jobs
curl -X GET http://localhost:5000/api/jobs
# Delete a job
curl -X DELETE http://localhost:5000/api/jobs/42
# Delete multiple jobs
curl -X POST http://localhost:5000/api/bulk/jobs \
-H "Content-Type: application/json" \
-d '{"action": "delete", "ids": [1, 2, 3, 4]}'
# Retry multiple jobs
curl -X POST http://localhost:5000/api/bulk/jobs \
-H "Content-Type: application/json" \
-d '{"action": "retry", "ids": [5, 6, 7, 8]}'
# Upload a file
curl -X POST http://localhost:5000/api/upload \
-F "file=@/path/to/document.pdf" \
-F "media_type=pdf"
Authorization: Bearer YOUR_TOKEN
header to all requests.
internal/api/server.go
. There are additional API endpoints available in internal/web/server.go
that provide extended functionality.