Note No playground link because this example relies on a KV Namespace.
Defines a /users/:username/todo
resource controller, storing all records inside a KV namespace:
GET /users/:username/todos
– lists allTodo
records for the:username
ownerPOST /users/:username/todos
– creates a newTodo
record for the:username
ownerGET /users/:username/todos/:uid
– retrieves a singleTodo
record, identified by the:username
:::uid
pairingPUT /users/:username/todos/:uid
– updates aTodo
record with new values, identified by the:username
:::uid
pairingDELETE /users/:username/todos/:uid
– deletes aTodo
record, identified by the:username
:::uid
pairing
Important: This is for demonstration purposes only! In order to be production-ready, it needs:
- Authentication / Authorization
Currently, any:username
value is accepted... and by anybody.- Proper input validation
Currently, only theinput.title
value is checked for a truthy-ness.- Stricter
uid
rules / route validation
Ideally you'd validate route-params likeuid
to protect against unnecessary KV interactions.
MIT