**Assignment Overview**

This assignment is worth 8% of your total grade. You must use the Express module and not the HTTP module. Using the HTTP module instead of Express will result in a score of 0. Additionally, using the ES6 import statement instead of the CommonJS require for Node modules will result in a 10% deduction.

**Specifications**

Rich Barton, the CEO of Zillow, needs assistance in developing a simple API to determine the Zestimates of houses and to fetch housing data easily. For this assignment, you will write an API server that listens on the port provided by the first argument to your program to provide details about a home.

**JSON API Server**

1. **Endpoint: `/v1/zillow/zestimate`**

- Write a server called `zillow.js` that serves JSON data when it receives a GET request to the path `/v1/zillow/zestimate`.
- The request should contain a query string with the keys `sqft`, `bed`, and `bath`, all of which are required integers.
- The Zestimate is calculated as follows:
\[
\text{Zestimate} = \text{sqft} \times \text{bed} \times \text{bath} \times 10
\]
- Return the JSON in the following format:
```json
{ "zestimate": Number }
```
- Example request: `/v1/zillow/zestimate?sqft=2000&bed=3&bath=4`
- Example JSON response:
```json
{ "zestimate": 240000 }
```

2. **Endpoint: `/v1/zillow/houses`**

- Add an endpoint that accepts an optional parameter `city`.
- If `city` is provided, return all houses that match the given city. If no `city` parameter is provided, return an empty array.
- If a city is provided and not found, return an empty array.
- Simulate a database with the following array of objects:
```json
[
{ "price": 240000, "city": "baltimore" },
{ "price": 300000, "city": "austin" },
{ "price": 400000, "city": "austin" },
{ "price": 1000000, "city": "seattle" },
{ "price": 325000, "city": "baltimore" },
{ "price": 550000, "city": "seattle" },
{ "price": 250000, "city": "boston" }
]
```
- Example request: `/v1/zillow/houses?city=baltimore`
- Example JSON response:
```json
[
{ "price": 240000, "city": "baltimore" },
{ "price": 325000, "city": "baltimore" }
]
```

- Example request: `/v1/zillow/houses?city=ralcigh`
- Example JSON response:
```json
[]
```

- Example request: `/v1/zillow/houses`
- Example JSON response:
```json
[]
```

3. **Endpoint: `/v1/zillow/prices`**

- Add an endpoint that accepts a required parameter `usd`.
- This will return all houses equal to or under the given price.
- If no houses are under the given price, return an empty array.
- Example request: `/v1/zillow/prices?usd=300000`
- Example JSON response:
```json
[
{ "price": 240000, "city": "baltimore" },
{ "price": 250000, "city": "boston" }
]
```

- Example request: `/v1/zillow/prices?usd=100000`
- Example JSON response:
```json
[]
```

**Response Codes**

- Return a 200 status code if the request is correct.
- Return a 404 status code if the request is incorrect (e.g., invalid endpoint, arguments, etc.).

Answer :

Below is the implementation of the zillow.js server that fulfills the given specifications using Express:

javascript

Copy code

const express = require('express');

const app = express();

const port = process.argv[2];

const houses = [

{ price: 240000, city: "baltimore" },

{ price: 300000, city: "austin" },

{ price: 400000, city: "austin" },

{ price: 1000000, city: "seattle" },

{ price: 325000, city: "baltimore" },

{ price: 550000, city: "seattle" },

{ price: 250000, city: "boston" }

];

app.get('/v1/zillow/zestimate', (req, res) => {

const { sqft, bed, bath } = req.query;

if (!sqft || !bed || !bath) {

res.sendStatus(400);

return;

}

const zestimate = sqft * bed * bath * 10;

res.json({ zestimate });

});

app.get('/v1/zillow/houses', (req, res) => {

const { city } = req.query;

if (city) {

const filteredHouses = houses.filter((house) => house.city === city);

res.json(filteredHouses);

} else {

res.json([]);

}

});

app.get('/v1/zillow/prices', (req, res) => {

const { usd } = req.query;

if (!usd) {

res.sendStatus(400);

return;

}

const filteredHouses = houses.filter((house) => house.price <= usd);

res.json(filteredHouses);

});

app.use((req, res) => {

res.sendStatus(404);

});

app.listen(port, () => {

console.log(`Server listening on port ${port}`);

});

Make sure you have Express installed (npm install express) before running this program.

Know more about javascripthere;

https://brainly.com/question/16698901

#SPJ11