Exercise: Build a Dynamic Web Server

Apply knowledge of HTTP servers, routing, content types, and parameters to create dynamic routes.

We'll cover the following...

Let’s practice what we’ve learned by creating a GET route and a POST route.

Instructions

  1. Add a GET route /greet that accepts two query parameters:

    1. name: The name of the person.

    2. language: The language in which to greet (e.g., en for English, es for Spanish).

    3. If both parameters are provided, respond with a greeting in the specified language. Example:

      1. For language=en, respond with "Hello, [name]!"

      2. For language=es, respond with "Hola, [name]!"

    4. If language is missing or unsupported, default to English.

    5. If name is missing, default to "guest".

  2. Add a POST route /uppercase that expects a JSON object in the request body with a key text.

    1. Convert the string in the text field to uppercase and respond with a JSON object containing the uppercase text.

    2. If the text field is missing, respond with a "400 Bad Request" and an error message.

Testing the HTTP server

Use the following curl commands to test your implementation: