- Objective - Implementat a sample API using Express, MongoDb, and Swagger
- Once respository is cloned locally, user can run either of these commands:
- node index.js - runs server locally; will need to stop, save, and re-run when modifying
- npm start - runs server locally; automatically re-runs after saving
- npm init -y - setup new project and creates package.json
- npm install express - installs express
- npm install mongodb - installs mongodb
- npm i mongoose - installs mongoose
- npm i dotenv - installs dotenv (used for environment variables)
- npm install --save-dev nodemon - installs nodemon
- npm install yamljs - installs yaml
- npm install swagger-ui-express - installs swagger UI
- npm install axios - installs axios (used to make request to 3rd party API)
- Tutorial to setup Express and MongoDb
- youtube.com/watch?v=30p9QfybWZg/
- Mongoose queries
- index.js
- The required libraries needed for Express, MongoDb, and Swagger
- Initializing express and using .env file for setting the port and mongodb url
- Setting up swagger for "/api-docs" endpoint
- Connecting to mongodb and using the PORT from env
- GET endpoints
- "/" returns a welcome message
- "/users" returns all users with 200 response or 500 response if there is server error
- "/users/:id/" returns one user based on id with 200 response, 404 if user cannot be found, or 500 if there is a server error
- POST endpoint
- "/users" creates a new user with 201 response, 400 if the body fails validation, or 500 if there is server error
- PUT endpoint
- "/users/:id" updates an existing user with 200 response, 404 if user cannot be found, 400 if the body fails validation, or 500 if there is a server error
- DELETE endpoint
- "/users/:id" deletes an existing user with 200 response, 404 if user cannot be found, or 500 if there is a server error
- user.js
- swagger.yaml
- The GET request for "/harry-potter-houses" makes a request to https://wizard-world-api.herokuapp.com/Houses/805fd37a-65ae-4fe5-b336-d767b8b7c73a which returns House Ravenclaw from its API
- The response from wizard-world-api is validated to ensure it has all of the required fields in the HarryPotterHouseSchema before being saved to HarryPotterHouse collection in MongoDB

























