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


4.2 Hello World UTF8

This example only differs from the previous in that the “Content-type” indicates UTF8 encoded data, and the hello world sent is selected at random from a list of different languages.

;;; hello-world-utf8.el --- utf8 hello world server using Emacs Web Server
(ws-start
 (lambda (request)
   (with-slots (process headers) request
     (let ((hellos '("こんにちは"
                     "안녕하세요"
                     "góðan dag"
                     "Grüßgott"
                     "hyvää päivää"
                     "yá'át'ééh"
                     "Γεια σας"
                     "Вiтаю"
                     "გამარჯობა"
                     "नमस्ते"
                     "你好")))
       (ws-response-header process 200
         '("Content-type" . "text/plain; charset=utf-8"))
       (process-send-string process
         (concat (nth (random (length hellos)) hellos) " world")))))
 9001)