High-Level Transformations

Paste It In

To save you the trouble of typing it, here's the request we used in the video.

Show Code

Hide Code

request = """
GET /wildthings HTTP/1.1
Host: example.com
User-Agent: ExampleBrowser/1.0
Accept: */*

"""

And here's the expected response:

Show Code

Hide Code

expected_response = """
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 20

Bears, Lions, Tigers
"""

Finally here are the three high-level transformations we used as a starting point.

Show Code

Hide Code

def parse(request) do
  # TODO: Parse the request string into a map:
  conv = %{ method: "GET", path: "/wildthings", resp_body: "" }
end

def route(conv) do
  # TODO: Create a new map that also has the response body:
  conv = %{ method: "GET", path: "/wildthings", resp_body: "Bears, Lions, Tigers" }
end

def format_response(conv) do
  # TODO: Use values in the map to create an HTTP response string:
  """
  HTTP/1.1 200 OK
  Content-Type: text/html
  Content-Length: 20

  Bears, Lions, Tigers
  """
end