---
# System prepended metadata

title: Tut05 Express Part 1

---

# Tut05 Express Part 1

- tut05/a.express

## 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 0 - /clear

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

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

---

## Group 1 - /addnameage

- Method: post
- Parameter Type:  name: string, age: number 

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

---

## Group 2 - /getnamesages

- Method: Get
- Parameter Type: minAge?: number

```ts=
console.log('TODO')
app.get('/getnamesages',(req: Request, res: Response) => {
    const minAge = req.query.minAge as string
    res.json(getnamesages(minAge ? parseInt(minAge) : undefined));
})
```

---

## Group 3 - /editnameage

- Method: Put
- Parameter Type: name: string, age: number

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

})
```

---

## Group 4 - /removenameage

- Method: 'DELETE'
- Parameter Type: name: string

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

## Group 5 - /getstats

- Method: GET
- Parameter Type: string

```ts
app.get("/getstats", (req: Request, res: Response) => {
    const {  } = res.query || {};
})
```

---

