Start building: a Redis cache API

Build a native API that writes, reads and deletes temporary Redis values. This Developer Trial includes typed JSON, validation tests and real HTTP checks in one project.

This example has no authentication and is for a local, disposable development environment. Bind it to loopback. It is a cache example with expiry, not a durable user database.

Install and check the SDK

Download and extract the complete SDK. Follow the installation page for your OS, then run doctor. Current platform results are listed in the release validation record.

# From the extracted SDK folder on macOS or Linux:
bash install.sh
threadone doctor

Create and test your project

threadone new cache-demo --template redis-api
cd cache-demo
threadone test
threadone build

The generated project includes models, service functions, routes, English and Thai guides, request examples and a smoke test. The native validation tests do not need Redis.

Run a local Redis fixture

Use an isolated local Redis instance with no real data. If redis-server is installed, this command runs a disposable fixture in a separate terminal without persistence. It does not install Redis.

redis-server --bind 127.0.0.1 --port 6379 --dir "$(mktemp -d)" --save "" --appendonly no

If port 6379 is already used, choose an unused port and change the URL below to match.

Start the native API

These commands are for a macOS or Linux shell. The generated README includes PowerShell commands. Plaintext Redis is allowed only for the explicit loopback opt-in below; remote Redis requires a rediss:// TLS URL.

export THREADONE_REDIS_URL='redis://127.0.0.1:6379'
export THREADONE_REDIS_ALLOW_LOCAL_PLAINTEXT=1
export THREADONE_BIND=127.0.0.1
export THREADONE_PORT=8080
threadone run

Make your first requests

Keep the API running and open another terminal in the project directory. The first call returns status 200 and {"ok":true}; the read returns your key and value.

curl -i http://127.0.0.1:8080/cache/set \
  -H 'Content-Type: application/json' \
  -d '{"key":"hello","value":"Hello from ThreadOne","ttl_ms":60000}'
curl -i http://127.0.0.1:8080/cache/get \
  -H 'Content-Type: application/json' -d '{"key":"hello"}'
curl -i http://127.0.0.1:8080/cache/delete \
  -H 'Content-Type: application/json' -d '{"key":"hello"}'

Deleting the key returns {"deleted":true}. A later read returns 404 and {"error":"Key not found"}.

Check the whole flow

python3 smoke.py --base-url http://127.0.0.1:8080

The optional smoke script needs Python 3 and calls the real local HTTP API. It uses unique trial keys and checks write/read/delete, missing keys, invalid JSON, empty values and expiry. Python is not required by the installed ThreadOne SDK or the application.

Know what the responses mean

HTTP statusMeaning
200The operation completed. The health route reports process liveness only; it does not check Redis.
400Invalid JSON, wrong field types or invalid key/value/TTL.
404The requested key is absent or has expired.
503Redis is unavailable. A failed write may have reached Redis; the template does not retry it automatically.

Keys are 1–256 Unicode characters with no surrounding whitespace. Values allow empty strings and up to 16,384 Unicode characters. TTL is 1–86,400,000 milliseconds. Stored keys use the threadone:trial: prefix.

Keep building

Edit src/lib/model.one for validation, src/lib/service.one for Redis behavior and src/main.one for routes. Run threadone test and the HTTP smoke script after changing the application.

The browser Playground runs pure language examples. This API needs the native SDK because it uses HTTP, Redis and file imports. Route paths are exact. SDK 0.11 adds bounded query/header lookups; path parameters, transactions and list-all operations remain outside this template.

Report a reproducible issue

threadone --version
threadone doctor

The generated issue-template.md asks for SDK version, OS, command, expected result, actual result and minimal source. Remove credentials, personal data and connection URLs before sharing. Nothing is sent automatically.