Counter API
A stateful HTTP API with in-memory counters. Demonstrates state management across requests.
Features Used
http- Enables theserve()function
Endpoints
Example Usage
# Get counter (auto-creates with value 0)
curl http://localhost:3000/counter/visitors
# {"name":"visitors","value":0}
# Increment
curl -X POST http://localhost:3000/counter/visitors/increment
# {"name":"visitors","value":1}
curl -X POST http://localhost:3000/counter/visitors/increment
# {"name":"visitors","value":2}
# Decrement
curl -X POST http://localhost:3000/counter/visitors/decrement
# {"name":"visitors","value":1}
# List all counters
curl http://localhost:3000/counters
# {"visitors":1}
# Reset
curl -X POST http://localhost:3000/counter/visitors/reset
# {"name":"visitors","value":0}Local Development
Run without installing tish (from this directory; tish repo is ../..):
# Run with interpreter
cargo run -p tishlang--manifest-path ../../Cargo.toml --release --features http -- run src/main.tish --features http
# Test incrementing
curl -X POST http://localhost:3000/counter/test/incrementOr with tish installed: tish run src/main.tish --features http
Deploy
Deploy with Zectre: zectre deploy --wait from this directory. See Deploy Overview for details.
Note on State
This example uses in-memory state. Counter values are lost when the process restarts. For production use, consider persisting state to a database or file system.