Use your new found EXPRESS skills to add some much needed clarity to your code from last night. Your task is to implement a real html interface from Agent Mulder, as he's getting tired of typing in the browser URL bar. You will do that in Express. Use the sightings.json
file from the previous homework.
The HTML form tag can be used to automatically send http requests. Forms can have many input fields. When a special submit button is clicked the browser grabs all the values for the input fields and generates query parameters, which it appends to the url and then sends as an http request. Here is a sample form which you should start with:
<!DOCTYPE html>
<html>
<head>
<title>The Xpress Files</title>
</head>
<body>
<h1>X-Finder</h1>
<form action="/search" method="get">
<label for="city">City</label>
<input type="text" name="city"/>
<button type="submit">Search</button>
</form>
</body>
</html>
When you click on the submit button this will send a GET
request to the path /search?city=<whatever-you-put-in-the-text-field>
.
- Initialize a new Express app
- Create an
index.html.ejs
view which will be our index page. Use the starter html provided. - Use Express to serve that view when the user goes to the root path
/
. (Note: The root route is often referred to as the index page) - Create a view which can show the information for a collection (array) of sightings.
- Create an express route
/search
which can handle the query for a city coming from the form. - Your route should render all the matched sightings.
- Add more fields to your search form so you can query by state, date, duration.
BONUS
- Explore the javascript
Date
object and the HTML input fieldtype="date"
. Implement a range date search. - Explore the html input field
type="select"
and allow for the user to select a state from a list. - Use client side javascript to generate a list of cities to select from, based on the state.
- Make it pretty! How do you include css!