This TypeScript project is a fully functional Express Application to manage adding, updating and listing users in a database managed by Sequelize. The purpose is to demostrate extensive usage of the express-typescript-decorators package. Linking the OpenAPI output from express-typescript-decorators
in this project with Swagger UI allows you to browse the capabilities and the generated API documentation.
- Complete and operational TypeScript API
- Database Models created with
sequelize-typescript
- Database Migration(s)
- Logging with
Winston
- Working
Express
Application - Token based authentication middleware
- Generated OpenAPI documentation
To get this project running locally, ensure you are running a Sequelize supported database and perform the following steps
npm install
- Copy
config/db.json.template
toconfig/db.json
- Populate
config/db.json
with valid database information
- Migrate the database
npm run migrate
- Copy
config/application.json.template
toconfig/application.json
- Populate
config/application.json
with any setting you prefer
- execute
npm run build
- Start the API
node dist/index.js
Once you have the API running locally, The best way to understand the capabilities of the API would be to point a running instance of Swagger UI to http://localhost:5000/api-docs
as the full OpenAPI documentation is hosted by the API in JSON format. For simplicity, this document also includes an overview of the available routes.
POST /api/user
example
curl -X 'POST' \
'http://localhost:5000/api/user/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"email": "paulforbes42@gmail.com",
"password": "L1m1t3dAcc355",
"firstName": "Paul",
"lastName": "Forbes"
}'
POST api/user/auth
example
curl -X 'POST' \
'http://localhost:5000/api/user/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"email": "paulforbes42@gmail.com",
"password": "L1m1t3dAcc355",
"firstName": "Paul",
"lastName": "Forbes"
}'
GET /api/user
requires auth
example (requires valid token)
curl -X 'GET' \
'http://localhost:5000/api/user/' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJhZGNlOTk0ZC1jYjY2LTRhMGYtODAzYS0yODU4MDk3NmViZTMiLCJpYXQiOjE2NjE5MjU5MTQsImV4cCI6MTY2MjAxMjMxNH0.7WXdPw06gFZu1QoPFj00pF7wrZ6_FokXSVQvU_4lpZ8'
PUT /api/user/:userId
requires auth
example (requires valid token, requires valid userId)
curl -X 'PUT' \
'http://localhost:5000/api/user/882f3812-d0fd-4679-86d7-1cfd3df4d056' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJhZGNlOTk0ZC1jYjY2LTRhMGYtODAzYS0yODU4MDk3NmViZTMiLCJpYXQiOjE2NjE5MjU5MTQsImV4cCI6MTY2MjAxMjMxNH0.7WXdPw06gFZu1QoPFj00pF7wrZ6_FokXSVQvU_4lpZ8' \
-H 'Content-Type: application/json' \
-d '{
"password": "L1m1t3dAcc355",
"firstName": "Test",
"lastName": "User"
}'
DELETE /api/user/:userId
requires auth
example (requires valid token, requires valid userId)
curl -X 'DELETE' \
'http://localhost:5000/api/user/882f3812-d0fd-4679-86d7-1cfd3df4d056' \
-H 'accept: */*' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJhZGNlOTk0ZC1jYjY2LTRhMGYtODAzYS0yODU4MDk3NmViZTMiLCJpYXQiOjE2NjE5MjU5MTQsImV4cCI6MTY2MjAxMjMxNH0.7WXdPw06gFZu1QoPFj00pF7wrZ6_FokXSVQvU_4lpZ8'
This project also has examples on how to write unit tests against your express-typescript-decorator
controllers.
npm run test