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
Add a GET route
/greetthat accepts two query parameters:name: The name of the person.language: The language in which to greet (e.g.,enfor English,esfor Spanish).If both parameters are provided, respond with a greeting in the specified language. Example:
For
language=en, respond with "Hello, [name]!"For
language=es, respond with "Hola, [name]!"
If
languageis missing or unsupported, default to English.If
nameis missing, default to "guest".
Add a POST route
/uppercasethat expects a JSON object in the request body with a keytext.Convert the string in the
textfield to uppercase and respond with a JSON object containing the uppercase text.If the
textfield 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: