/yesod-hello-world

Simple application written in the Yesod web framework.

Primary LanguageHaskellBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

yesod-hello-world

docs

This is a simple application built to learn the Yesod Haskell web framework.

Run Server

Start the server locally at http://localhost:3000 using

stack run

Request/response examples

Valid routes are defined at config/routes.yesodroutes. The default response type is JSON, but HTML is also supported by using the Accept content negotiation header field.

/ GET

  • Request:
    curl http://localhost:3000
    Response:
    {"greeting":"Hello, World!"}
  • Request:
    curl 'http://localhost:3000/?name=Artem'
    Response:
    {"greeting":"Hello, Artem!"}
  • Request:
    curl http://localhost:3000 -H 'Accept: text/html'
    Response:
    <!DOCTYPE html>
    <html><head><title></title></head><body>Hello, World!</body></html>
  • Request:
    curl 'http://localhost:3000/?name=Artem' -H 'Accept: text/html'
    Response:
    <!DOCTYPE html>
    <html><head><title></title></head><body>Hello, Artem!</body></html>

/ POST

  • Request:
    curl -X POST http://localhost:3000 -H 'Content-Type: application/json' -d '{"name":"Artem"}'
    Response:
    {"greeting":"Hello, Artem!"}
  • Request:
    curl -X POST http://localhost:3000 -H 'Content-Type: application/json' -d '{"name":"Artem"}' -H 'Accept: text/html'
    Response:
    <!DOCTYPE html>
    <html><head><title></title></head><body>Hello, Artem!</body></html>

/{name} GET

  • Request:
    curl 'http://localhost:3000/Artem'
    Response:
    {"greeting":"Hello, Artem!"}
  • Request:
    curl 'http://localhost:3000/Artem' -H 'Accept: text/html'
    Response:
    <!DOCTYPE html>
    <html><head><title></title></head><body>Hello, Artem!</body></html>