Todo API template for AntelopeJS in TypeScript, with database models, JWT authentication and generated CRUD routes.
A todo API built on AntelopeJS: decorated database tables and models, JWT authentication, an HTTP controller, and CRUD routes generated by the data API.
my-todo/
├── src/
│ ├── index.ts # start() registers the database schema
│ ├── db/
│ │ ├── tables/ # User (hashed password) and Task tables
│ │ └── models/ # UserModel and TaskModel
│ ├── routes/auth.ts # /auth/register, /auth/login, /auth/me
│ └── data-api/tasks.ts # /tasks CRUD routes, each scoped to the caller's tasks
├── test/
│ ├── example.test.ts # calls the API of the running module
│ └── task-ownership.test.ts # one user cannot reach another user's tasks
├── antelope.config.ts # written by ajs project init and ajs project modules install
├── antelope.test.ts # test configuration: API, auth-jwt and an in-memory MongoDB
├── package.json
└── tsconfig.json
Create a project from this template and add the modules that implement its interfaces (@antelopejs/api, @antelopejs/auth-jwt and @antelopejs/mongodb):
npx @antelopejs/core project init my-todo --template todo-app-typescript
cd my-todo
npx @antelopejs/core project modules install --yesnpx @antelopejs/core project modules install --yes adds the three modules to antelope.config.ts with a default configuration. It serves the API on http://localhost:8080, connects to MongoDB at mongodb://localhost:27017, and sets a placeholder JWT secret. Change the secret and the connection string there before you deploy.
Two modules implement @antelopejs/interface-database: @antelopejs/mongodb and @antelopejs/rethinkdb. --yes adds the first one listed, @antelopejs/mongodb, without asking, so the command also runs in CI, a script or an agent. Without --yes, the command asks in a terminal which database module to add (pick @antelopejs/mongodb), and it stops with exit code 2 when there is no terminal to ask in.
Start a MongoDB server on localhost:27017, then run the project:
npx @antelopejs/core project dev --watchRegister, log in, and send the token in the x-antelopejs-auth header:
curl -X POST localhost:8080/auth/register -d '{"email":"me@example.com","password":"secret"}'
TOKEN=$(curl -s -X POST localhost:8080/auth/login -d '{"email":"me@example.com","password":"secret"}' | node -pe 'JSON.parse(require("fs").readFileSync(0)).token')
curl -X POST localhost:8080/tasks/new -H "x-antelopejs-auth: $TOKEN" -d '{"title":"Try AntelopeJS"}'
curl localhost:8080/tasks/list -H "x-antelopejs-auth: $TOKEN"| Method | Route | What it does |
|---|---|---|
POST |
/auth/register |
Creates a user |
POST |
/auth/login |
Returns a JWT |
GET |
/auth/me |
Returns the authenticated user |
GET |
/tasks/list |
Lists your tasks (paginated) |
GET |
/tasks/get?id=<id> |
Returns one of your tasks |
POST |
/tasks/new |
Creates a task that you own |
PUT |
/tasks/edit?id=<id> |
Updates one of your tasks |
DELETE |
/tasks/delete?id=<id> |
Deletes your tasks among ids |
The /tasks routes and /auth/me answer 401 without a token and 403 with an invalid or expired one. Each /tasks route reaches only the caller's tasks. new takes userId from the token and sets createdAt and updatedAt, edit refreshes updatedAt, get and edit answer 404 for a task of another user as for a missing one, and delete skips such ids.
pnpm testajs module test builds the module and starts it with the API, auth-jwt and MongoDB modules. The tests need no running service. antelope.test.ts starts a throwaway MongoDB with mongodb-memory-server-core and serves the API on a free port. The first run downloads a MongoDB binary into ~/.cache/mongodb-binaries. Set MONGOMS_SYSTEM_BINARY to use a mongod you already have.
If you rename the module in package.json, rename it in antelope.config.ts and antelope.test.ts too.
- Full-stack tutorial: this application, built step by step.
- Database, Authentication and Data API: the guides behind each part.
- Testing: write module tests.
Using Claude Code or Codex? Install the AntelopeJS agent skills plugin so your agent knows the framework and its CLI.
See CONTRIBUTING.md. Run pnpm install then pnpm run checks before you open a pull request.
This template belongs to AntelopeJS, the TypeScript framework where modules depend on contracts and the application chooses the provider. The open-source back office AntelopeJS DMS is built on it.