emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 10/119: some simple examples


From: Eric Schulte
Subject: [elpa] 10/119: some simple examples
Date: Mon, 10 Mar 2014 16:57:00 +0000

eschulte pushed a commit to branch master
in repository elpa.

commit dbaeb3d98697fd204a1591f1a7e10db3a9247fab
Author: Eric Schulte <address@hidden>
Date:   Wed Dec 18 13:53:43 2013 -0700

    some simple examples
---
 examples/0-hello-world.el      |   18 ++++++++++++++++++
 examples/1-hello-world-utf8.el |   31 +++++++++++++++++++++++++++++++
 examples/2-hello-world-html.el |   26 ++++++++++++++++++++++++++
 examples/3-post-echo.el        |   28 ++++++++++++++++++++++++++++
 4 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/examples/0-hello-world.el b/examples/0-hello-world.el
new file mode 100644
index 0000000..d69d652
--- /dev/null
+++ b/examples/0-hello-world.el
@@ -0,0 +1,18 @@
+;;; hello-world.el --- simple hello world server using Emacs Web Server
+
+;; Copyright (C) 2013 Eric Schulte <address@hidden>
+
+;; Author: Eric Schulte <address@hidden>
+;; Keywords: hello http
+;; License: GPLV3 (see the COPYING file in this directory)
+
+;;; Code:
+(require 'emacs-web-server)
+
+(ews-start
+ '(((lambda (_) t) .
+    (lambda (proc request)
+      (ews-response-header proc 200 '("Content-type" . "text/plain"))
+      (process-send-string proc "hello world")
+      :finished)))
+ 9000)
diff --git a/examples/1-hello-world-utf8.el b/examples/1-hello-world-utf8.el
new file mode 100644
index 0000000..66ab1d9
--- /dev/null
+++ b/examples/1-hello-world-utf8.el
@@ -0,0 +1,31 @@
+;;; hello-world-utf8.el --- utf8 hello world server using Emacs Web Server
+
+;; Copyright (C) 2013 Eric Schulte <address@hidden>
+
+;; Author: Eric Schulte <address@hidden>
+;; Keywords: hello http
+;; License: GPLV3 (see the COPYING file in this directory)
+
+;;; Code:
+(require 'emacs-web-server)
+
+(ews-start
+ '(((lambda (_) t) .
+    (lambda (proc request)
+      (let ((hellos '("こんにちは"
+                      "안녕하세요"
+                      "góðan dag"
+                      "Grüßgott"
+                      "hyvää päivää"
+                      "yá'át'ééh"
+                      "Γεια σας"
+                      "Вiтаю"
+                      "გამარჯობა"
+                      "नमस्ते"
+                      "你好")))
+        (ews-response-header proc 200
+          '("Content-type" . "text/plain; charset=utf-8"))
+        (process-send-string proc
+          (concat (nth (random (length hellos)) hellos) " world")))
+      :finished)))
+ 9001)
diff --git a/examples/2-hello-world-html.el b/examples/2-hello-world-html.el
new file mode 100644
index 0000000..d94347b
--- /dev/null
+++ b/examples/2-hello-world-html.el
@@ -0,0 +1,26 @@
+;;; hello-world-html.el --- html hello world server using Emacs Web Server
+
+;; Copyright (C) 2013 Eric Schulte <address@hidden>
+
+;; Author: Eric Schulte <address@hidden>
+;; Keywords: hello http
+;; License: GPLV3 (see the COPYING file in this directory)
+
+;;; Code:
+(require 'emacs-web-server)
+
+(ews-start
+ '(((lambda (_) t) .
+    (lambda (proc request)
+      (ews-response-header proc 200 '("Content-type" . "text/html"))
+      (process-send-string proc "<html>
+  <head>
+    <title>Hello World</title>
+  </head>
+  <body>
+    <b>hello world</b>
+  </body>
+</html>
+")
+      :finished)))
+ 9002)
diff --git a/examples/3-post-echo.el b/examples/3-post-echo.el
new file mode 100644
index 0000000..5f0f932
--- /dev/null
+++ b/examples/3-post-echo.el
@@ -0,0 +1,28 @@
+;;; post-echo.el --- echo back posted message using Emacs Web Server
+
+;; Copyright (C) 2013 Eric Schulte <address@hidden>
+
+;; Author: Eric Schulte <address@hidden>
+;; Keywords: http post
+;; License: GPLV3 (see the COPYING file in this directory)
+
+;;; Code:
+(require 'emacs-web-server)
+
+(ews-start
+ '(((:POST . ".*") .
+    (lambda (proc request)
+      (let ((message (cdr (assoc "message" request))))
+        (ews-response-header proc 200 '("Content-type" . "text/plain"))
+        (process-send-string proc
+          (if message
+              (format "you said %S\n" (cdr (assoc 'content message)))
+            "This is a POST request, but it has no \"message\".\n"))
+        :finished)))
+   ((:GET . ".*") .
+    (lambda (proc request)
+      (ews-response-header proc 200 '("Content-type" . "text/plain"))
+      (process-send-string proc
+        "This is a GET request not a POST request.\n")
+      :finished)))
+ 9003)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]