Why you should port Scheme application to GNU Artanis
Wait! I don't use GNU Guile! Why bother to read this?
Yes, and I'm glad that you know GNU Artanis is written with GNU Guile. And I'm also happy that you know GNU Artanis is CURRENTLY implemented with Guile specifice features. But please be patient, you can still write standard Scheme code, say RnRS standard code, and take advantage of GNU Artanis. This article will show you how to port your Scheme webapp to GNU Artanis.
I want to see a best practice first!
Sure! Recently, I've helped to port byggstep, a CI/CD project in Scheme to GNU Artanis. It's a cool project, you may want to take a look: https://codeberg.org/jjba23/byggsteg I just passed by this project a few days ago, and I've spent my weekend 2 hours to read through the code, and port it to GNU Artanis. Fortunately, it's still in early stage, so the code is not that complex. But it's a good example to show you how to port a Scheme webapp to GNU Artanis. Here's a detailed discussion: https://codeberg.org/jjba23/byggsteg/issues/1
Why webapp matters nowadays?
To my experience, webapp is a good way to show your project to the world. And it solves GUI design for any Scheme application.
What about the portablity?
GNU Artanis is a web framework written in GNU Guile. There's historical reason for this. It's possible to port GNU Artanis to RnRS, however, we need R7RS-large. I'm full confident with R7RS-large, since it defines many library standard, include FFI and delimited-continuations, which is the critical feature for the server-core of GNU Artanis.
On the other hande. GNU Artanis seperate the code into two parts: the MVC and library. Folks may put their project to the library path, and write a compatible layer to call Artanis APIs. Just like you port your application to any other Operating System.
What does it look like after porting?
First, we are talking about the general application with GUI. So it's suitable for MVC pattern.
You just need to write controllers, and that's simple, let's see the byggsteg example:
(define-artanis-controller jobs) (import (byggsteg html)) (get "/jobs/request" #:mime 'xml (lambda (rc) (response-emit (:mime rc (job-request-form-page))))) (post "/jobs/manage/submit" job-submit-endpoint) (post "/jobs/manage/delete" job-delete-endpoint)
Easy, right? post is the HTTP method, (http-method path controller), the controller is defined in the original of byggsteg project. And we put it in lib/byggsteg directory, which will be detected by GNU Artanis. It's so simple to import it with (import (byggsteg html)).
The deeper implementation was hidden in the byggsteg project, and most of the code is reusable. The most of the porting work is to decide how to intereact with the client or browser. Today, cool guys make want to just return JSON, and let the modern web frontend framework like React or Vue to render the GUI.
What's the benefit of porting to GNU Artanis?
It depends on your plan, if transfer your Scheme application to webapp is a good idea for you, then GNU Artanis, as a product level web framework since 2013, is a good choice. It's stable, strong server-core based on delimited-continuation, well designed, and easy to use. And it's GNU project, respect your freedom.
How to start?
You may want to take a look at the byggsteg project first, and then read the GNU Artanis manual: https://www.gnu.org/software/artanis/manual/manual.html. Then, try a simple case to learn how to write a controller, and how to interact with the client. Anyway, you can always ask for help in the mailing list: [email protected]
Happly hacking!