Building a simple contact management REST API using Node.js, TypeScript, Koa.js.
Requirements
- MVC pattern
- Dependency Injection
- Authentication
- Database, MongoDB support, migration
- Models: Contact, Category
- REST API, Json interface
- Unit tests
Useful links:
Packages
Build:
- TypeScript
- TSLint
- ts-node
- chockidar
- concurrently
Using direct command line tools with npm script.
Test:
- Jest (or Mocha)
Core:
- Koa
Database:
- Sequalizer
- Mongoose
Authentication
- Passport?
Requirements
Data models
- contact
- category
- user
Contact
- id
- name (string)
- email (string)
- category (belongsTo)
Category
- id
- name
- contacts (hasMany)
User
- id
- username
- password
- email
Resource endpoints
path | method | |
---|---|---|
/api/categories |
GET | list all record |
/api/categories |
POST | create a new category record |
/api/categories/:id |
GET | get the individual record |
/api/categories/:id |
PUT | update the whole record |
/api/categories/:id |
DELETE | get the individual record |
/api/contacts |
GET | |
/api/contacts |
POST | |
/api/contacts/:id |
GET | |
/api/contacts/:id |
PUT | |
/api/contacts/:id |
DELETE |
Authentication
Following Passport.js patterns: http://www.passportjs.org/docs/authenticate/
- Create
/api/categories
route- Add test
- Add implementation
- Investigating RESTyped: https://github.com/rawrmaan/restyped
- Article