MCPcopy Index your code
hub / github.com/TomDoesTech/REST-API-Tutorial-Updated

github.com/TomDoesTech/REST-API-Tutorial-Updated @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
34 symbols 97 edges 26 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Build a REST API with Node.js, Mongoose & TypeScript

Note: This repository includes the postman collection for the finished API

Note 2: Make sure you add .env to your .gitignore before pushing any changes to your repository. You will also want to generate new public & private keys

Generate new keys: https://travistidwell.com/jsencrypt/demo/

Base64 encode the keys: https://www.base64encode.org/

Common issues

  • I'm getting a JWT malformed error: https://youtu.be/FzKrfwplips
  • Managing environment variables: https://youtu.be/gfyQzeBlLTI

Who is this tutorial for?

  • Junior to mid-level developers
  • Anyone interested in building REST APIs with TypeScript

What you will need

  • A running instance of MongoDB
  • Postman
  • An IDE or text editor (VS Code)
  • A web browser
  • A package manager such as NPM or Yarn
  • Node.js installed

What next?

  • Testing the API with Jest
  • Build a React.js user interface
  • Add Prometheus metrics to the API
  • Deploy the API with Caddy & Docker
  • Add Google OAuth

Concepts

  • REST API principals
    • CRUD
    • HTTP methods
  • JWT & refresh tokens
  • Request validation

Technologies

  • Node.js
  • MongoDB with Mongoose
  • TypeScript
  • Express.js & Express.js middleware
  • Zod validation

Video structure

  1. What are we going to build (Postman demo)
  2. Code walk-through
  3. Bootstrap application
  4. Setup express JS
  5. Create routes function
  6. Setup database connection
  7. Setup logger
  8. Validate request middleware
  9. Registration
  10. Create user model
  11. Create user endpoint
  12. Create user session
  13. Deserialize user middleware (refresh tokens)
  14. Get sessions
  15. Delete session
  16. Require user middleware
  17. Product resource
  18. Create product model
  19. Create product
  20. Read product
  21. Update product
  22. Delete product

Data flow

Access & refresh token flow

Deployment

What will we use

  • Docker (image)
  • docker-compose (container)
  • Caddy - Web server
  • DigitalOcean

Note: You will need Docker installed locally if you want to test your Docker configutation

Let's keep in touch

Buy me a Coffee

Sign up to DigitalOcean 💖

Extension points exported contracts — how you extend this code

ProductInput (Interface)
(no doc)
src/models/product.model.ts
ProductDocument (Interface)
(no doc)
src/models/product.model.ts
UserInput (Interface)
(no doc)
src/models/user.model.ts
UserDocument (Interface)
(no doc)
src/models/user.model.ts
SessionDocument (Interface)
(no doc)
src/models/session.model.ts

Core symbols most depended-on inside this repo

signJwt
called by 3
src/utils/jwt.utils.ts
verifyJwt
called by 3
src/utils/jwt.utils.ts
findProduct
called by 3
src/service/product.service.ts
routes
called by 1
src/routes.ts
swaggerDocs
called by 1
src/utils/swagger.ts
startMetricsServer
called by 1
src/utils/metrics.ts
connect
called by 1
src/utils/connect.ts
createSession
called by 1
src/service/session.service.ts

Shape

Function 28
Interface 5
Method 1

Languages

TypeScript100%

Modules by API surface

src/service/session.service.ts4 symbols
src/service/product.service.ts4 symbols
src/controller/product.controller.ts4 symbols
src/service/user.service.ts3 symbols
src/models/user.model.ts3 symbols
src/controller/session.controller.ts3 symbols
src/utils/jwt.utils.ts2 symbols
src/models/product.model.ts2 symbols
src/utils/swagger.ts1 symbols
src/utils/metrics.ts1 symbols
src/utils/connect.ts1 symbols
src/routes.ts1 symbols

Datastores touched

ProductCollection · 1 repos
SessionCollection · 1 repos
UserCollection · 1 repos
(mongodb)Database · 1 repos
rest-api-tutorialDatabase · 1 repos

For agents

$ claude mcp add REST-API-Tutorial-Updated \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact