[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)
- [elpa] 02/119: logging support, (continued)
- [elpa] 02/119: logging support, Eric Schulte, 2014/03/10
- [elpa] 03/119: parsing HTTP headers, Eric Schulte, 2014/03/10
- [elpa] 01/119: initial commit, echo server working, Eric Schulte, 2014/03/10
- [elpa] 04/119: simple hello world server working, Eric Schulte, 2014/03/10
- [elpa] 05/119: stub out (but don't write any) tests, Eric Schulte, 2014/03/10
- [elpa] 08/119: NOTES file for tasks and notes, Eric Schulte, 2014/03/10
- [elpa] 07/119: TODO: handle post data, Eric Schulte, 2014/03/10
- [elpa] 06/119: helper for HTTP headers, Eric Schulte, 2014/03/10
- [elpa] 09/119: parsing form data in POST, Eric Schulte, 2014/03/10
- [elpa] 11/119: more flexible network process creation, Eric Schulte, 2014/03/10
- [elpa] 10/119: some simple examples,
Eric Schulte <=
- [elpa] 15/119: more lenient parsing of multipart forms, Eric Schulte, 2014/03/10
- [elpa] 12/119: compiling to .elc, Eric Schulte, 2014/03/10
- [elpa] 13/119: tasks, Eric Schulte, 2014/03/10
- [elpa] 18/119: 404 not found helper, Eric Schulte, 2014/03/10
- [elpa] 17/119: handling errors, Eric Schulte, 2014/03/10
- [elpa] 14/119: better requirements for test, Eric Schulte, 2014/03/10
- [elpa] 16/119: tasks, Eric Schulte, 2014/03/10
- [elpa] 20/119: don't require non-nil return to close connection, Eric Schulte, 2014/03/10
- [elpa] 19/119: simply (name . content) for form elements, Eric Schulte, 2014/03/10
- [elpa] 21/119: helper to send a file with mime type, Eric Schulte, 2014/03/10