How do I create a web application using LISP?
Asked Answered
P

3

11

I have experience in C# and JavaScript, and have been working for the last few years with Node.js. Basically, I'm very confident with this environment, but one language has always caught my eye: LISP. I find it impressive and quite fascinating how expressive LISP is, given its minimal language concepts. It's basically as with jQuery: Do more with less ;-)

Unfortunately, my experience with LISP is more or less theoretical and some playing around, but not serious programming.

Now I'd like to change that, but I am definitely dedicated to web application development (hence Node.js). My problem is not to learn LISP as a language, my problem is that I do not know where and how to start with a "Hello LISP world" application that is not console-based, but web-based.

So, my question basically is: How could I write a server-side web application in LISP that is similar to the following Node.js application

var http = require('http');
http.createServer(function (req, res) {
  res.end('Hello world!');
}).listen(3000);

without the need for lots of frameworks and additional libraries and stuff and so on?

How would an experienced LISP programmer solve this task? Any hints?

Petulia answered 11/8, 2013 at 14:17 Comment(8)
Maybe you should consider using CGI.Dissert
Well, yes, this may be an idea - although I dislike the "plugin" approach of CGI. But it may be an idea ... thanks for pointing this out!Petulia
you should probably check: #556956Moony
Thanks, this looks quite interesting!Petulia
If Emacs is an acceptable platform, have a look at Elnode.Contreras
Could you expand on your request for having this be "without the need for lots of frameworks and additional libraries and stuff and so on"? Are you expecting everything to be built in to the core language, and/or built by hand by you, or do you want to know about frameworks and libraries that make this stuff easy? In the latter case, you already have some answers that point to useful tools, though there are more that could be added (cl-who is a useful add-on, for example)... if the former, I'd want to understand why, to best answer you.Edrei
Basically what I meant was that I'd like to be able to do this with as least overhead as possible: So, no over-architected and highly-sophisticated solution, just a simple one, short and compact.Petulia
There is TBLN vy WEITZ or ClakcBrandabrandais
O
21

Once you have SBCL and Quicklisp installed,

(ql:quickload "hunchentoot")
(hunchentoot:start 
  (make-instance 'hunchentoot:easy-acceptor :port 3000))
(hunchentoot:define-easy-handler (foo :uri "/bar") (name)
  (format nil "Hello~@[ ~A~]!" name))

Then visit

http://127.0.0.1:3000/bar?name=World
Opulence answered 11/8, 2013 at 16:26 Comment(0)
H
9

The answer about Hunchentoot is really a way to go for starters, and I fully recommend to try it.

The only major difference from the node.js variant in the question is that Hunchentoot is a synchronous web-server. If you want to get the same asynchronous behavior (actually, why would you, but that's for another discussion ;), you've got to try something else, like wookie. The similar Hello World example is procided at its documentation page.

Hereat answered 11/8, 2013 at 19:39 Comment(1)
Thanks for the Wookie mention! I would also recommend Hunchentoot for starters. The synchronous model is about 5x easier to wrap your head around. Where Wookie really shines is when you need an app to tie different pieces together (calling out to internal or 3rd party APIs via HTTP, running database queries, grabbing values from redis, queuing larger jobs to the background, etc...anything that requires network I/O). It's not meant to do much "work" other than encoding/decoding and passing data around. Beware also, async driver support is lacking. Your favorite DB probably isn't supported (yet)Atlantis
G
8

Just as to complement other answers, there are also ningle1 and caveman2, which also are decently documented. Ningle routing is very similar to Sinatra/Flask.

Girondist answered 12/8, 2013 at 8:46 Comment(1)
I have had a really good time with Caveman. Would recommend it to anyone.Surber

© 2022 - 2024 — McMap. All rights reserved.