Web Application Programming in PicoLisp: Setting up the server

Search for a command to run...

No comments yet. Be the first to comment.
In this series, we will show how to create a basic web application in PicoLisp.
In the last post, we started the server and hosted a minimal "Hello World"-script. The resulting HTML source consisted of a single <body> tag. Today we will show how to add further tags. HTML tags functions HTML tags are used to structure the page. ...
In our previous post, we introduced how to utilize Discrete Event Simulation (DES) in PicoLisp. Now, let's explore another application: a railroad model simulation that includes tracks and trains. The visualization is ASCII-based, so feel free to unl...

The Dining Philosophers

In this post, we will introduce the concept of co-routines and how they are handled in PicoLisp. This will be the foundation for the subsequent posts on Discrete Event Simulation and finally a couple of examples, including an ASCII model railway simu...

One of the many nice things of PicoLisp is that it comes with a built-in database. This makes it easy to collect and store our own data, for example via a mobile app. But not all data is best represented in tables and lists: sometimes a colorful litt...

In the last two posts, we have built a little app that shows the current location and displays the nearest ice cream shops: https://picolisp-explored.com/an-openstreetmap-app-written-in-picolisp-pt-1 https://picolisp-explored.com/an-openstreetmap-ap...

Now that we know how to create a HTTP-response out of a PicoLisp script, let's set up a server and try it out.
When speaking of servers, many people think of large, specialized computers that are stored somewhere under the earth and do secret, mysterious stuff.
But in its most basic meaning, a server is just a piece of software that does just this: serving things to other program (the clients). Of course this can also happen within just one computer. In this case, we call it "application server" or "local server", as opposed to the "web server" that can be accessed via the internet.
Processes that are accessible by other processes are running on so-called ports. These ports are "communication endpoints", which means that the client is sending the request to this location. In theory, any port number between 1 and 65535 can be used. In practice, there are standard ports for different applications.
Now let's see it in action.
What job does our PicoLisp server have? Well, when the browser asks for a specific file, for example "helloworld.l", it needs to ask the PicoLisp interpreter to execute that file before sending it to the client.
But before we do that, we should save our "hello world"-example from the last post to file. Otherwise our server will have nothing to serve. Create a file called helloworld.l with the following content:
(html 0 "Hello" NIL NIL
(prinl "Hello World!") )
Now let's start the server with this command from the command line:
$ pil @lib/http.l @lib/xhtml.l @lib/form.l --server 8080 +
What do we do here? First, we load three libraries: @lib/http.l, @lib/xhtml.l and @lib/form.l, as we will need these to successfully render our html-pages. Then we specify the server and port number by --server <port-number>. The + at the end opens the debugging mode, which is helpful to see what is going on.
Now we want to open the file helloworld.l from the browser. So point your browser towards http://localhost:8080/helloworld.l to see the output:

Why "localhost"? localhost refers to the current computer. Since the PicoLisp server is only running locally, you will not be able to view this page from a system outside your computer.
What happens if we try to open a file that does not exist, for example error.l? In this case, the debugger will throw an error:
$ pil @lib/http.l @lib/xhtml.l @lib/form.l --server 8080 +
!? (load File)
"error.l" -- Open error: No such file or directory
We can stop the server with Ctrl-C.
Our "Hello World" text looks quite lonely. Let's see how we can wrap it into some HTML tags in the next post.
https://software-lab.de/doc/app.html