Next: , Previous: , Up: Usage Examples   [Contents][Index]

4.1 Hello World

The simplest possible “hello world” example. The handler consists of a single (matcher . handler) pair. The function matcher matches every incoming HTTP request. The handler responds by setting the content type to text/plain, and then sending the string “hello world”. When the handler exits the network connection of the request is closed.

;;; hello-world.el --- simple hello world server using Emacs Web Server
 (lambda (request)
   (with-slots (process headers) request
     (ws-response-header process 200 '("Content-type" . "text/plain"))
     (process-send-string process "hello world")))