Simple todo list API implemented in Node.js.
The todo items are saved in the data/todos.json
file.
- Install dependencies with
npm install
- Start the API with
npm start
- Check that the API is running by visiting http://localhost:3000/healthz.
- Test out the API, see API documentation
- Run tests with
npm run test
Variable | Description |
---|---|
SECRET |
Used for checking if the user is allowed to use the GET /stats endpoint |
DATABASE_URL |
Database URL for the POST /increment endpoint |
Endpoint | Description | Example curl command |
---|---|---|
GET /healthz |
Returns "OK" if the API is running | curl -XGET 'http://localhost:3000/healthz' |
GET /todos |
Fetch all todo items | curl -XGET 'http://localhost:3000/todos' |
GET /todos/:id |
Fetch one todo item | curl -XGET 'http://localhost:3000/todos/1' |
POST /todos |
Create new todo item |
curl -XPOST 'http://localhost:3000/todos' \
--header 'Content-Type: application/json' \
--data '{"content": "Hello world"}' |
PUT /todos/:id |
Update one todo item |
curl -XPUT 'http://localhost:3000/todos/1' \
--header 'Content-Type: application/json' \
--data '{"content": "Hello world"}' |
DELETE /todos/:id |
Delete one todo item | curl -XDELETE 'http://localhost:3000/todos/1' |
GET /stats |
Returns statistics of all todo items, requires secret | curl -XGET 'http://localhost:3000/stats?secret=verysecret' |
POST /increment |
Increments a counter, requires a PostgreSQL database | curl -XPOST 'http://localhost:3000/increment' |