About Clack
Upcoming SlideShare
Loading in...5
×
 

About Clack

on

  • 19,153 views

This is a presentation for International Lisp Conference 2012 which was held in Kyoto, Japan. ...

This is a presentation for International Lisp Conference 2012 which was held in Kyoto, Japan.

Clack is a web application environment for Common Lisp to make your web applications be portable and reusable by abstracting HTTP into a simple API.

In this paper, I describe what are problems in web development and how Clack solves them.

Statistics

Views

Total Views
19,153
Views on SlideShare
2,474
Embed Views
16,679

Actions

Likes
4
Downloads
16
Comments
0

15 Embeds 16,679

http://clacklisp.org 14262
http://d.hatena.ne.jp 2115
http://blog.8arrow.org 193
http://translate.googleusercontent.com 58
https://twitter.com 31
http://honyaku.yahoofs.jp 4
http://www.excite-webtl.jp 3
http://webcache.googleusercontent.com 3
https://si0.twimg.com 3
http://prlog.ru 2
https://www.google.sk 1
http://reader.aol.com 1
https://www.google.com 1
http://twitter.com 1
http://www.google.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Hello, everyone. My name is Eitarow Fukamachi.\nI’m very happy now. Today is my first presentation in English.\nMy English is not good, but I'll do my best.\n
  • First of all, I know my name is hard to pronounce for non-Japanese speaker. My name is pronounced like “eight arrow”. Please call me “eight arrow” or “eight”.\nI live in Kyoto. I have been a Common Lisp user since 2010.\nThis is my second attendance of ILC. I attended the previous one at Reno.\nIt was really exciting experience for me. Many people often asked me “Which language do you use?” Of course, I said “I use Common Lisp”. Then immediately he said “Which one?” I got confused. At that time I understood that “Lisp” is not only one language for us. SBCL and CLISP is slightly different. Many people at there wanted to know which implementation I used.\nI’m using Clozure CL for my hobby programming. It is slower than SBCL, but it’s compilation speed is reliable.\nI work at a company called Hatena as a web application developer. I love Web, I love Lisp, but I still use Perl at work.\n
  • Let me introduce some of my Common Lisp products.\nI wrote 11 Common Lisp libraries and all of them are available on Quicklisp.\nMost of them are related to web. Web frameworks, a database interface, a template engine and so on.\nIn this session, I would like to introduce something I made called “Clack”. If you are a web application enginner or web framework developper, this session would be interesting for you.\n
  • What’s “Clack”?\n
  • Clack is a “Web application environment”. Which means it is a foundation for a Web application or a Web application framework.\nIt makes web applications portable and reusable by abstracting HTTP into a simple API.\nThis is equivalent to Python’s WSGI, Ruby’s Rack, Perl’s Plack/PSGI and Clojure’s Ring. These middlewares has become imperative in Web anymore.\n
  • Clack is built with two ideas in mind -- “Portability” and “Reusability”.\n
  • First, I’d like to talk about Clack’s portability.\n
  • Some years ago, web application and web application frameworks need to have web server adapters for each web server.\nThis figure is really complicated and ugly.\nClack changes this to...\n
  • ...this. It’s pretty simple. Each application has only to know the interface of Clack.\nClack aims to make a web application work on many web servers without changing any code. Web application based on Clack don’t need to know what web server is behind it.\nThis allows running an application on different backend for different environments. It is possible to run an application on Hunchentoot during development, and then use a faster backend like FastCGI for your production environment.\n
  • Here is some sample code.\n“clackup” is a function to start a Clack server.\nClack uses Hunchentoot as it’s backend by default.\n
  • It can be changed by passing the :server keyword.\nIf you pass “:fcgi” to it, FastCGI server will be started.\nIf you pass “:apache” to it, Apache2 + mod_lisp proxy server will be started as well.\n\nNow, as a result of this abstraction, we obtain another possibility.\n
  • It is “Reusability”\n
  • In Clack, an application takes a request and just returns a response. Since it’s simple, it is easy to extend.\n
  • Clack has an extension mechanism called “Middleware”.\nMiddlewares surround Applications. It takes a request before Application takes it and gets the Response which Application generates. By wrapping an Application, Middleware allows you to change the Application’s behavior without rewriting the existing code.\nAs Middlewares are completely separated from Application, they can be reused other Applications.\n
  • Now, I’ll show you 4 examples of Clack in use.\n
  • First, “Hello, World” -- it’s the most famous example.\n
  • This is a program to display a string “Hello, World!” in your browser.\n“App” is a simple web application.\nIt is just a function which takes exactly one argument “env” and returns a list containing exactly three values -- HTTP status, headers and body.\n
  • Highlighted strings are the request and the response.\n
  • “Env” is something like this. It is just a property-list.\nSome people may wonder why the request isn’t a CLOS object.\nThis is because it’s quite simpler. A property-list is easy to understand how to deal with it.\nIt doesn’t require any dependencies.\nThis simple interface allows you to extend applications easily.\nI’ll show you the example a little later.\n
  • After “clackup”, “Hello, World!” would be displayed in your browser.\n
  • The second example of Clack has a conditional flow in an app.\n
  • This sample code shows different content for what the request path is.\nThis app would serve favicon.ico if the request path is "/favicon.ico", "Hello again" for the request to the root (/) and otherwise 404.\nThis is a simple URL dispatcher.\n
  • My next example of Clack uses Basic Authentication.\n
  • Here is some sample code. The “app” is the same as the first one.\nA macro “builder” builds the app and middlewares into an app.\n“” is a Clack middleware. It adds Basic Authentication to an app without rewriting the app. This authenticator means only the user Dr. “John McCarthy” is allowed.\n
  • This code will show you a page like this.\nI hope the internet is also available in heaven.\n
  • My final example of Clack is more practical.\n
  • This will serve static files when the pathname starts with “/images/”, “/css/” or “/js/”.\nIt emits the directory names and searchs a file to serve from “static” directory.\n
  • Now I will tell you about the benefits of using Clack.\n
  • Your usage of Clack depends on who you are.\nIf you’re a “Web framework developer”, Clack provides server interfaces. You don’t have to write adapters for each web server. Moreover, Middlewares will be help to build up your framework.\n
  • If you’re a “Web application engineer”, you can get benefits to use web frameworks built on Clack.\nThe benefit of a framework built on Clack is that the design is loosely coupled. Some parts of it are made as Clack Middlewares, which means developers can remove or replace parts of a framework as necessary.\n
  • I introduce you 2 frameworks built on Clack.\n
  • Caveman is a Sinatra-like micro framework.\nIt has the minimum set of features required for web applications -- a URL-based dispatcher, an adapter to a template engine, and a database interface.\nningle is even smaller. It provides only a URL-based dispatcher.\n
  • See these URLs for more detail.\nBoth of them are already available on Quicklisp.\n
  • \n
  • \n
  • Finally, I would like to talk about Clack’s future.\n
  • I have almost completed Clack’s core, but I need to improve it a little more.\nI have to increase the bundled middleware and web server adapters.\nI’m looking for a high-performance non-blocking web server and a preforking web server.\nIf you know something about it, please let me know that after this.\n
  • And now, there are only 2 frameworks, and I hope more frameworks will be built on Clack.\nBoth of them are really small. So I think a full-stack framework such as Ruby on Rails for Common Lisp should exist.\n
  • \n
  • Are there any questions in “easy” English?\n

About Clack About Clack Presentation Transcript

  • About Clack Hatena Co., Ltd. Eitarow Fukamachi Oct 24, 2012 International Lisp Conference @ Kyoto, Japan
  • About Me• Eitarow FUKAMACHI (≒ eight arrow)• Live in Kyoto, Japan• Common Lisp user since 2010• Attended ILC2010 @ Reno• (I’m using Clozure CL)• Web application developer at Hatena Co., Ltd.• Using Perl at work
  • Products• Clack • CL-Markup• Caveman • CL-Project• ningle • Shelly• CL-TEST-MORE etc.• CL-DBI See github.com/fukamachi
  • What’s “Clack”?
  • What’s Clack?• Web application environment • Foundation for Web application framework• Equivalent to... • Python’s WSGI, Ruby’s Rack, Perl’s Plack/PSGI and Clojure’s Ring
  • What’s Clack?• Web application environment • Foundation for Web application framework• Equivalent to... • Python’s WSGI, Ruby’s Rack, Perl’s Plack/PSGI and Clojure’s Ring• Abstract HTTP into a simple API (Portability)• Share code across web frameworks (Reusability)
  • Clack’s“Portability”
  • “Portability”• Abstract a web server ※Application includes Web frameworks.
  • “Portability”• Abstract a web server ※Application includes Web frameworks.
  • “Portability”(clack:clackup app);-> Hunchentoot server is started.; Listening on localhost:5000.; # #x30200A102B3D
  • “Portability”(clack:clackup app);-> Hunchentoot server is started.; Listening on localhost:5000.; # #x30200A102B3D(clack:clackup app :server :hunchentoot) ;; default(clack:clackup app :server :fcgi)(clack:clackup app :server :apache)
  • Clack’s“Reusability”
  • “Reusability”• Application takes Request and returns Response
  • “Reusability”• Application takes Request and returns Response• Extension mechanism called “Middleware”• “Middleware” can be reused
  • “Show me how to use it!”
  • Example 1“Hello, World!”
  • Example: Hello, World!(defun app (env) (declare (ignore env)) (200 (:content-type "text/plain") ("Hello, World!")))(clack:clackup #app)
  • Example: Hello, World!(defun app (env) (declare (ignore env)) (200 ‘(200 (:content-type "text/plain") “text/plain”) ("Hello, World!"))) (“Hello, World!”))(clack:clackup #app)
  • Example: Hello, World! (defun app (env) (declare (ignore env)) (200 ‘(200(:request-method :GET :script-name "" (:content-type "text/plain") “text/plain”) :path-info "/sns/member" ("Hello, World!"))) (“Hello, World!”)) :query-string "id=3":server-name "localhost":server-port 5000 (clack:clackup #app):request-uri "/sns/member?id=3":server-protocol :HTTP/1.1:http-user-agent "Mozilla/5.0 (Macintosh...":remote-addr "127.0.0.1":remote-port 26077:http-referer nil:http-host "localhost:5000":http-cookies nil)
  • Example: Hello, World!
  • Example 2“Conditional flow”
  • Example: Conditional flow(defun app (env) (cond ((string= (getf env :path-info) "/favicon.ico") (200 (:content-type "image/x-icon") #p"/path/to/favicon.ico")) ((string= (getf env :path-info) "/") (200 (:content-type "text/html") ("Hello again"))) (t (404 (:content-type "text/plain") ("Not found")))))(clack:clackup #app)
  • Example 3“Basic Auth”
  • Example: Basic Auth(import ‘(clack.builder:builder clack.middleware.auth.basic:<clack-middleware-auth-basic>))(defun app (env) (declare (ignore env)) (200 (:content-type "text/plain") ("Hello, World!")))(clack:clackup (builder (<clack-middleware-auth-basic> :authenticator (lambda (user pass) (and (string= user "johnmccarthy") (string= password "password")))) #app))
  • Example: Basic Auth
  • Example 4“Static files”
  • Example: Static files(import ‘(clack.builder:builder clack.middleware.static:<clack-middleware-static>))(defun app (req) (declare (ignore req)) (200 (:content-type "text/plain") ("Hello, World!")))(clack:clackup (builder (<clack-middleware-static> :path (lambda (path) (when (ppcre:scan "^/(?:images|css|js)/" path) (ppcre:regex-replace "^/[^/]+" path ""))) :root #p"static/") #app))
  • What are the benefits of using Clack?
  • Clack allows you to:• If you’re a “Web framework developer”... • Clack provides server interfaces. • Reuse code from other web frameworks.
  • Clack allows you to:• If you’re a “Web framework developer”... • Clack provides server interfaces. • Reuse code from other web frameworks.• If you’re a “Web application engineer”... • Reuse code in your projects • Extensible
  • Frameworks
  • Frameworks• Caveman • A Sinatra-like micro framework• ningle • A really micro framework
  • Frameworks• Caveman (fukamachi.github.com/caveman/) • A Sinatra-like micro framework• ningle (fukamachi.github.com/ningle/) • A really micro framework
  • Future Work
  • Future Work• More Middlewares• More Servers • non-blocking web server? • preforking web server?
  • Future Work• More Middlewares• More Servers • non-blocking web server? • preforking web server?• More Frameworks • Ruby on Rails?
  • THE ENDThank you for listening
  • Maybe we still have time. Any questions in easy English? To Japanese speakers: Please translate a question for me if it looks I dont understand it. 僕が質問を理解できていなさそうだったら翻訳してください><