---
# System prepended metadata

title: 'Day 08: `pg`, Express Router, Wizard News Exit Ticket Solutions'

---

# Day 08: `pg`, Express Router, Wizard News Exit Ticket Solutions

**You should be able to:**

- Describe the role of pg in our stack
- Define REST and its advantages
- Create and mount Express Routers
- Explain the role of body parsing middleware

## What role does node-postgres assume when communicating with postgres?

- Client: It is requesting something from the PostgreSQL server ☑️
- Server
- Neither

## What is REST?

- A node module for handling routes
    - Express
- A type of built-in express middleware for designing routers
    - Express Router
- An architectural style for designing web services ☑️
    - Helps answer the question on how to organize routes and how to map functionality to URIs and Methods:
        - Paths represent "nouns" or resources
        - HTTP “verbs” map to data operations
- A algorithm for parsing the text of an HTTP request
    - Body Parser

## Select all HTTP verbs

- GET
- POST
- PUT
- DELETE

## What is the express body parser and why do we use it?

It's a piece of middleware in which it extracts data from a form and makes it available to `req.body`. This is needed because data on the internet is not necessarily sent in wholesale but in packets.

# Exit Ticket Questions

> how exactly did they make it so that the "submit" button on the 'add' route (gotten from a get request) end up making the input you submit on that form become the req.params of the post route. Was there something in the html strings that was allowing that?

It's in the live demo from yesterday as well, but basically, that `get` request just shows the page with the form. If you go into `views/addPost.js` and look at what's highlighted below, it's saying, "this is a POST request and we are going to /posts"

![](https://i.imgur.com/DZoba9n.png)

---

> explain the router part and all the const/exports needed

Also, explained in yesterday's Router lecture that I re-uploaded

Below is the top of the Router file I want to separate my pokemon routes into
I need to have express, and I will use the `Router` method to declare this is an Express Router
I also included the `pg` client because this file is where I will be doing the SQL queries
![](https://i.imgur.com/csMiLPc.png)

This is the bottom of that `pokemonRoutes.js` file. In order to use it, I need to export it
![](https://i.imgur.com/xb0Aut3.png)

This is the top of my `index.js` file, and note I `required` the `pokemonRoutes.js` file

As well as declared it in `app.use` to be used as middleware. Refer to below diagram for more info on how everything runs for the most part
![](https://i.imgur.com/eEirXxZ.png)

---

## Diagram from this morning
![](https://i.imgur.com/xorb4BV.jpg)
