hello.scm 1.0 KB

123456789101112131415161718192021222324252627282930
  1. ;;; Commentary:
  2. ;;; A simple web server that responds to all requests with the eponymous
  3. ;;; string. Visit http://localhost:8080 to test.
  4. ;;; Code:
  5. (use-modules (web server))
  6. ;; A handler receives two values as arguments: the request object, and
  7. ;; the request body. It returns two values also: the response object,
  8. ;; and the response body.
  9. ;;
  10. ;; In this simple example we don't actually access the request object,
  11. ;; but if we wanted to, we would use the procedures from the `(web
  12. ;; request)' module. If there is no body given in the request, the body
  13. ;; argument will be false.
  14. ;;
  15. ;; To create a response object, use the `build-response' procedure from
  16. ;; `(web response)'. Here we take advantage of a shortcut, in which we
  17. ;; return an alist of headers for the response instead of returning a
  18. ;; proper response object. In this case, a response object will be made
  19. ;; for us with a 200 OK status.
  20. ;;
  21. (define (handler request body)
  22. (values '((content-type . (text/plain)))
  23. "Hello, World!"))
  24. (run-server handler)