Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TomDoesTech/REST-API-Tutorial-Updated
https://github.com/TomDoesTech/REST-API-Tutorial-Updated
mongodb nodejs rest-api tutorial typescript zod
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/TomDoesTech/REST-API-Tutorial-Updated
- Owner: TomDoesTech
- Created: 2021-10-03T02:35:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-09T04:29:25.000Z (over 1 year ago)
- Last Synced: 2024-04-17T06:07:25.431Z (9 months ago)
- Topics: mongodb, nodejs, rest-api, tutorial, typescript, zod
- Language: TypeScript
- Homepage: https://www.youtube.com/watch?v=BWUi6BS9T5Y
- Size: 153 KB
- Stars: 527
- Watchers: 12
- Forks: 275
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - TomDoesTech/REST-API-Tutorial-Updated - (TypeScript)
README
# Build a REST API with Node.js, Mongoose & TypeScript
Note: This repository includes the [postman collection for the finished API](postman_collection.json)
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
1. Setup express JS
2. Create routes function
3. Setup database connection
4. Setup logger
5. Validate request middleware
4. Registration
1. Create user model
2. Create user endpoint
3. Create user session
4. Deserialize user middleware (refresh tokens)
5. Get sessions
6. Delete session
7. Require user middleware
5. Product resource
1. Create product model
2. Create product
3. Read product
4. Update product
5. Delete product## Data flow
![](./diagrams/data-flow.png)## Access & refresh token flow
![](./diagrams/refresh-token-flow.png)# Deployment
## What will we use
* Docker (image)
* docker-compose (container)
* Caddy - Web server
* DigitalOceanNote: You will need Docker installed locally if you want to test your Docker configutation
## Let's keep in touch
- [Subscribe on YouTube](https://www.youtube.com/TomDoesTech)
- [Discord](https://discord.gg/4ae2Esm6P7)
- [Twitter](https://twitter.com/tomdoes_tech)
- [TikTok](https://www.tiktok.com/@tomdoestech)
- [Facebook](https://www.facebook.com/tomdoestech)
- [Instagram](https://www.instagram.com/tomdoestech)[Buy me a Coffee](https://www.buymeacoffee.com/tomn)
[Sign up to DigitalOcean 💖](https://m.do.co/c/1b74cb8c56f4)