]> code.delx.au - gnu-emacs-elpa/blob - packages/web-server/examples/005-post-echo.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / web-server / examples / 005-post-echo.el
1 ;;; post-echo.el --- echo back posted message using Emacs Web Server
2 ;; Copyright (C) 2014 Free Software Foundation, Inc.
3
4 (ws-start
5 '(((:POST . ".*") .
6 (lambda (request)
7 (with-slots (process headers) request
8 (let ((message (cdr (assoc "message" headers))))
9 (ws-response-header process 200 '("Content-type" . "text/plain"))
10 (process-send-string process
11 (if message
12 (format "you said %S\n" (cdr (assoc 'content message)))
13 "This is a POST request, but it has no \"message\".\n"))))))
14 ((:GET . ".*") .
15 (lambda (request)
16 (with-slots (process) request
17 (ws-response-header process 200 '("Content-type" . "text/plain"))
18 (process-send-string process
19 "This is a GET request not a POST request.\n")))))
20 9005)