You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.8 KiB
2.8 KiB
Phomnemic
A phonemic encoding/decoding system with dictionary management and REST API.
Configure and Run
Prerequisites
- Rust 1.70 or later
- SQLite (for local database)
- Firebase Auth (optional, for JWT authentication)
Installation
cargo build --release
Configuration
Create a config.toml file in the project root:
[listen]
host = "0.0.0.0"
port = 3000
log_level = "info"
[auth]
firebase_project_id = "your-firebase-project-id"
firebase_emulator_url = "http://localhost:9099"
api_tokens = ["your-api-key-1", "your-api-key-2"]
[database]
url = "sqlite:app.db"
Authentication Options
The application supports two authentication methods:
-
Firebase JWT Authentication (for frontend clients)
- Set
firebase_project_idto your Firebase project ID - Or use
firebase_emulator_urlfor local development with Firebase Auth Emulator
- Set
-
API Key Authentication (for server-to-server or CLI access)
- Add valid API keys to the
api_tokensarray - Send requests with
X-API-Keyheader containing your API key
- Add valid API keys to the
Running with Firebase Auth Emulator
-
Start the Firebase Auth Emulator:
firebase emulators:start --only authThe emulator runs on port 9099 by default.
-
Configure the application to use the emulator:
[auth] firebase_emulator_url = "http://localhost:9099" api_tokens = ["dev-api-key"] -
Get a test token from the emulator:
# Using curl curl -X POST "http://localhost:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=fake-api-key" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "password": "password", "returnSecureToken": true }' -
Make authenticated requests:
curl -X GET "http://localhost:3000/api/v1/info" \ -H "Authorization: Bearer <your-firebase-token>"
Running with API Keys
-
Configure API keys in
config.toml:[auth] api_tokens = ["my-secret-api-key"] -
Make authenticated requests:
curl -X GET "http://localhost:3000/api/v1/info" \ -H "X-API-Key: my-secret-api-key"
Starting the Server
cargo run --release -- listen
Or with custom options:
cargo run --release -- listen --host 127.0.0.1 --port 8080
API Endpoints
info Check
GET /api/v1/info
Dictionary Management
GET /api/v1/dicts
GET /api/v1/dicts/:name
Major System Encoding/Decoding
POST /api/v1/major/encode
POST /api/v1/major/decode
Authentication
POST /api/v1/auth/login
Development
Run in development mode with auto-reload:
cargo run -- listen
Testing
Run tests:
cargo test
License
MIT