|
2 | 2 | ## Web Apps in Lisp: Know-how |
3 | 3 |
|
4 | 4 | You want to write a web application in Common Lisp and you don't know |
5 | | -where to start? Or you don't want to re-invent the wheel? Follow the guide. |
6 | | - |
7 | | - |
8 | | -## Why Common Lisp |
9 | | - |
10 | | -For web development as for any other task, one can leverage Common |
11 | | -Lisp's advantages: |
12 | | - |
13 | | -- the **unmatched REPL** that even helps to interact with a running web app on your remote server, |
14 | | -- the **exception handling system**, |
15 | | -- **performance**, |
16 | | -- easy deployment: ability to build **self-contained executables** containing all our static files, |
17 | | -- **stability**, |
18 | | -- **good threads story**, |
19 | | -- **strong** and incremental **typing**, |
20 | | -- etc. |
21 | | - |
22 | | -All the development experience is very much interactive, allowing us |
23 | | -to write and test features right away. **There are no compile times** |
24 | | -during development, we only need to compile the app from scratch once in |
25 | | -a while, to check that our dependencies or the project layout are |
26 | | -correctly declared. |
27 | | - |
28 | | -We can, for example, define a new route and try it right away, **we |
29 | | -don't wait for a local web server** to pick up the changes and |
30 | | -restart. In case of an error, the interactive debugger pops up (if we |
31 | | -want to), **no server will crash because of an undefined variable** |
32 | | -(looking at you, Python). We can edit a function and compile it with a |
33 | | -keyboard shortcut (the usual `C-c C-c` in Slime): we can compile our |
34 | | -code *one function at a time*. The **feedback is |
35 | | -immediate**. |
36 | | - |
37 | | -We can **choose the degree of interactivity**: the web server |
38 | | -can catch exceptions and fire the interactive debugger, or print lisp |
39 | | -backtraces on the browser, or display a 404 error page and print logs |
40 | | -on standard output. The ability to build self-contained executables |
41 | | -eases deployment tremendously (compared to, for example, npm-based |
42 | | -apps), in that we just copy the executable to a server and run it. |
43 | | - |
44 | | -But we can also run it as a "script" from sources. |
45 | | - |
46 | | -In both cases, when we have deployed it, we can still **interact |
47 | | -with the running application**, allowing for **hot code reload**. We |
48 | | -can even install new dependencies while it is running, no process has |
49 | | -to restart. Of course, if we prefer to be careful and we don't want to use live |
50 | | -reload capabilities, we might still enjoy this capability to reload, for example, |
51 | | -a user's configuration file. |
52 | | - |
53 | | -So Common Lisp can be a good choice for web development too. The |
54 | | -ecosystem has lots of little or not so little libraries, including a |
55 | | -production-ready, battle proven web framework (Hunchentoot). |
56 | | - |
57 | | -However, **we don't have a batteries-included web framework easily |
58 | | -usable by novice web developers** (yet…). But now you have this guide. |
| 5 | +where to start? You are a beginner in web development, or a lisp |
| 6 | +amateur looking for clear and short pointers about web dev in Lisp? |
| 7 | +You are all at the right place. |
| 8 | + |
59 | 9 |
|
60 | 10 | ## What's in this guide |
61 | 11 |
|
62 | | -We'll present here some established web frameworks and other common |
63 | | -libraries to help you getting started in developing a web |
64 | | -application. We do *not* aim to be exhaustive nor to replace the |
65 | | -upstream documentation. |
66 | | - |
67 | | -We will learn: |
68 | | - |
69 | | -- how to start a simple web project with the Hunchentoot web server |
70 | | - - defining routes |
71 | | - - returning any content type, including JSON |
72 | | - - serving HTML |
73 | | - - HTML will be written in HTML, with a Django-like template engine (Djula), or a more flexible template engine (Ten, but Djula is already very flexible) |
74 | | - - we will show how to write HTML in s-expressions (with Spinneret) |
75 | | -- how to connect to a database, how to define models |
76 | | - - how to serialize and deserialize the models to and from JSON |
77 | | -- how to debug a running web app |
78 | | -- how to serve JavaScript |
79 | | - - how to make AJAX calls to our Lisp backend |
80 | | - - with pure JavaScript |
81 | | - - with Vue.js |
82 | | - - with the ISSR lisp library |
83 | | - - with the HTMX library |
84 | | -- how to create user login |
85 | | -- how to build and deploy a project |
86 | | - - with executables |
87 | | - - with SystemD |
88 | | - - how to configure Nginx |
89 | | - - how to setup third-party service providers (Sentry, Plausible web analytics, Graphana…) |
90 | | -- how to set up a Continuous Integration system |
91 | | -- how to build a Debian package. |
92 | | - |
93 | | -Your feedback and contributions are appreciated! |
94 | | - |
95 | | -**In [part 1](/part-1/), we will get to know a classical stack: Hunchentoot, easy-routes for easier routing and Djula templates.** |
96 | | - |
97 | | -In part 2, we will add interactivity on the client side, with or without JavaScript. |
98 | | - |
99 | | -In part 3, we will build an interactive Ajax-based Todo-app without writing any JavaScript, thanks to ISSR and Weblocks. |
100 | | - |
101 | | -Now let's start with a [libraries overview](/part 1/). |
102 | | - |
103 | | - |
104 | | -{{% notice note %}} |
105 | | -🎥 If you need to learn Common Lisp, good news, [I am creating this video course on Udemy](https://www.udemy.com/course/common-lisp-programming/?referralCode=2F3D698BBC4326F94358). |
106 | | -{{% /notice %}} |
| 12 | +We'll start with a **tutorial** that shows the essential building blocks: |
107 | 13 |
|
108 | | -{{% notice info %}} |
| 14 | +- starting a web server |
| 15 | +- defining routes |
| 16 | +- grabbing URL parameters |
| 17 | +- rendering templates |
| 18 | +- and running our app from sources, or building a binary. |
109 | 19 |
|
110 | | -If you find similar content from the Cookbook, this is normal. I am the main contributor and I wrote the web page there. This guide wants to be more complete and more advanced. |
| 20 | +We'll build a simple page that presents a search form, filters a list of |
| 21 | +products and displays the results. |
111 | 22 |
|
112 | | -{{% /notice %}} |
| 23 | + |
113 | 24 |
|
114 | 25 |
|
115 | | -{{% notice info %}} |
| 26 | +The **building blocks** section is organized by topics, so that with a |
| 27 | +question in mind you should be able to look at the table of contents, pick the right page and go ahead. |
116 | 28 |
|
117 | | -Here's a 5 minutes refresh on how to create a project, how to run it from sources, how to build a binary and how to load everything in SLIME: |
| 29 | +We hope that it will be plenty useful to you. |
118 | 30 |
|
119 | | -{{% /notice %}} |
| 31 | +Don't hesitate to share what you're building! |
120 | 32 |
|
121 | | -{{< youtube XFc513MJjos >}} |
| 33 | +{{% notice info %}} |
| 34 | +🎥 If you want to learn Common Lisp efficiently, with a code-driven approach, good news, [I am creating a video course](https://www.udemy.com/course/common-lisp-programming/?referralCode=2F3D698BBC4326F94358) on the Udemy platform. Learn more and get coupons [here](https://github.com/vindarel/common-lisp-course-in-videos/). I also have [Common Lisp tutorial videos on Youtube](https://www.youtube.com/@vindarel). |
| 35 | +{{% /notice %}} |
122 | 36 |
|
| 37 | +Now let's go to [the tutorial](/tutorial/). |
| 38 | + |
| 39 | +## Contact |
| 40 | + |
| 41 | +We are @vindarel on [Discord's Lisp server](https://discord.gg/hhk46CE) and Mastodon. We can use Github |
| 42 | +Discussions for anything CL + web related. |
| 43 | + |
| 44 | + |
| 45 | +<!-- ## Keywords --> |
| 46 | + |
| 47 | +<!-- We will learn: --> |
| 48 | + |
| 49 | +<!-- - how to set up a project, with an .asd system definition and a package --> |
| 50 | +<!-- - how to develop interactively, re-compiling our definitions as we go --> |
| 51 | +<!-- - how to start a web project, using the Hunchentoot web server --> |
| 52 | +<!-- - defining routes and using query parameters --> |
| 53 | +<!-- - serving HTML and rendering templates --> |
| 54 | +<!-- - we will mainly write plain HTML with the Djula templating engine --> |
| 55 | +<!-- - but we'll also show how to write HTML in s-expressions with the Spinneret library --> |
| 56 | +<!-- - how to debug a running web app --> |
| 57 | +<!-- - how to connect to a database --> |
| 58 | +<!-- - how to create a JSON web API --> |
| 59 | +<!-- - how to serve JavaScript and static assets --> |
| 60 | +<!-- - how to make AJAX calls to our Lisp backend --> |
| 61 | +<!-- - with JavaScript --> |
| 62 | +<!-- - with the HTMX library --> |
| 63 | +<!-- - with Vue.js --> |
| 64 | +<!-- - with an isomorphic Common Lisp web framework --> |
| 65 | +<!-- - how to create users with a login page --> |
| 66 | +<!-- - how to build and deploy a project --> |
| 67 | +<!-- - with executables --> |
| 68 | +<!-- - with SystemD --> |
| 69 | +<!-- - how to configure Nginx --> |
| 70 | + |
| 71 | + |
| 72 | +<!-- {{< youtube XFc513MJjos >}} --> |
| 73 | + |
| 74 | + |
| 75 | +<!-- ## Why Common Lisp --> |
| 76 | + |
| 77 | +<!-- For web development as for any other task, one can leverage Common --> |
| 78 | +<!-- Lisp's advantages: --> |
| 79 | + |
| 80 | +<!-- - the **unmatched REPL** that even helps to interact with a running web app on your remote server, --> |
| 81 | +<!-- - the **exception handling system**, --> |
| 82 | +<!-- - **performance**, --> |
| 83 | +<!-- - easy deployment: ability to build **self-contained executables** containing all our static files, --> |
| 84 | +<!-- - **stability**, --> |
| 85 | +<!-- - **good threads story**, --> |
| 86 | +<!-- - **strong** and incremental **typing**, --> |
| 87 | +<!-- - etc. --> |
| 88 | + |
| 89 | +<!-- All the development experience is very much interactive, allowing us --> |
| 90 | +<!-- to write and test features right away. **There are no compile times** --> |
| 91 | +<!-- during development, we only need to compile the app from scratch once in --> |
| 92 | +<!-- a while, to check that our dependencies or the project layout are --> |
| 93 | +<!-- correctly declared. --> |
| 94 | + |
| 95 | +<!-- We can, for example, define a new route and try it right away, **we --> |
| 96 | +<!-- don't wait for a local web server** to pick up the changes and --> |
| 97 | +<!-- restart. In case of an error, the interactive debugger pops up (if we --> |
| 98 | +<!-- want to), **no server will crash because of an undefined variable** --> |
| 99 | +<!-- (looking at you, Python). We can edit a function and compile it with a --> |
| 100 | +<!-- keyboard shortcut (the usual `C-c C-c` in Slime): we can compile our --> |
| 101 | +<!-- code *one function at a time*. The **feedback is --> |
| 102 | +<!-- immediate**. --> |
| 103 | + |
| 104 | +<!-- We can **choose the degree of interactivity**: the web server --> |
| 105 | +<!-- can catch exceptions and fire the interactive debugger, or print lisp --> |
| 106 | +<!-- backtraces on the browser, or display a 404 error page and print logs --> |
| 107 | +<!-- on standard output. The ability to build self-contained executables --> |
| 108 | +<!-- eases deployment tremendously (compared to, for example, npm-based --> |
| 109 | +<!-- apps), in that we just copy the executable to a server and run it. --> |
| 110 | + |
| 111 | +<!-- But we can also run it as a "script" from sources. --> |
| 112 | + |
| 113 | +<!-- In both cases, when we have deployed it, we can still **interact --> |
| 114 | +<!-- with the running application**, allowing for **hot code reload**. We --> |
| 115 | +<!-- can even install new dependencies while it is running, no process has --> |
| 116 | +<!-- to restart. Of course, if we prefer to be careful and we don't want to use live --> |
| 117 | +<!-- reload capabilities, we might still enjoy this capability to reload, for example, --> |
| 118 | +<!-- a user's configuration file. --> |
| 119 | + |
| 120 | +<!-- So Common Lisp can be a good choice for web development too. The --> |
| 121 | +<!-- ecosystem has lots of little or not so little libraries, including a --> |
| 122 | +<!-- production-ready, battle proven web framework (Hunchentoot). --> |
| 123 | + |
| 124 | +<!-- However, **we don't have a batteries-included web framework easily --> |
| 125 | +<!-- usable by novice web developers** (yet…). But now you have this guide. --> |
123 | 126 |
|
124 | 127 | [hunchentoot]: https://edicl.github.io/hunchentoot |
125 | 128 | [clack]: https://github.com/fukamachi/clack |
|
0 commit comments