---
# System prepended metadata

title: Tut05 Express Part 1

---

# Tut05 Express Part 1

- Template for tut05/a.express - https://hackmd.io/recent

## Starter Code

- For tutor to modify

```ts
import express, { json, Request, Response } from 'express';
import morgan from 'morgan';
import { port, url } from './config.json';
import {
  clear,
  addNameAge,
  editNameAge,
  getNamesAges,
  getStats,
  removeNameAge,
} from './names.ages';

const app = express();

app.use(json());
// For debugging purposes - logs http requests
app.use(morgan('dev'));

// TODO TUTOR 0: /clear

// TODO GROUP 1: /addnameage

// TODO GROUP 2: /getnamesages

// TODO GROUP 3: /editnameage

// TODO GROUP 4: /removenameage

// TODO GROUP 5: /getstats

app.listen(port, () => {
  console.log(`Starting Express Server at the URL: '${url}:${port}'`);
});
```


## Tutor - /clear

- Method: `DELETE`
- Parameter Type: `Query`

```ts
app.delete('/clear', (req: Request, res: Response) => {
    res.json(clear());
});
```

---

## Tutor - /addnameage

- Method: `POST`
- Parameter Type: `Body`

```ts
app.post('/addnameage', (req: Request, res: Response) => {
    const { name, age } = req.body;
    res.json(addNameAge(name, age));
});
```

---

## Group AERO - /getnamesages

- Method: Get
- Parameter Type: 

app.get('/addnamemessages', (req: Request, res: Response) => {
    const { name, m } = req.body;
    res.json(addnamemessages(name, messages));
});

```ts
app.get('/addnamemessages', (req: Request, res: Response) => {
    const { name, m } = req.body;
    res.json(addnamemessages(name, messages));
});
});
```

---

## Group BOOST - /editnameage

- Method: put
- Parameter Type: body

```ts
app.put('/editnameage', (req: Request, res: Response) => {
    const { name, age } = req.body;
    res.json(editNameAge(name, age));
})
```

---

## Group CRUNCHIE - /removenameage

- Method: DELETE
- Parameter Type: { name: string }

```ts
app.delete('/removenameage',(req: Request, res: Response) => {
	const returnValue = removeNameAge(req.body.name);
	res.json(returnValue);
})
```
---

## Group DREAM - /getstats

- Method: 'GET'
- Parameter Type: {}

```ts
app.get('/getstats', (req: Request, res: Response) => {
    res.json(getStats())
})



```

---


https://www.google.com/search?q=hellohellohello&rlz=1C1CHBF_en-GBAU910AU910&sxsrf=AJOqlzV1M74VI0vmppNUDHa05jUmcGnvuw%3A1678689839803&ei=L8YOZMbWMLDl2roP0pGrKA&ved=0ahUKEwiGqtv8ptj9AhWwslYBHdLICgUQ4dUDCA8&uact=5&oq=hellohellohello&gs_lcp=Cgxnd3Mtd2l6LXNlcnAQA0oECEEYAFAAWABgAGgAcAF4AIABAIgBAJIBAJgBAA&sclient=gws-wiz-serp