/aws-training-api

Starting point for the hands-on AWS training.

Primary LanguageJavaScript

aws-training-api

Simple todo list API implemented in Node.js.

The todo items are saved in the data/todos.json file.

Getting started

  1. Install dependencies with npm install
  2. Start the API with npm start
  3. Check that the API is running by visiting http://localhost:3000/healthz.
  4. Test out the API, see API documentation

Running tests

  • Run tests with npm run test

Environment variables

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

API documentation

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'