Urgent.News

What's breaking now, across thousands of outlets.

Tech

Exploring Janet and the httpf web framework

Janet is a programming language that the author finds appealing, despite their previous struggles with Lisp and Scheme. This language comes with a decent standard library, including a module called httpf which functions as a minimal web framework. The author decided to create a server using this framework to better understand how it works. They started by making a server object and defining functions with the :path metadata, which the server later uses to locate these functions.

The HTTPF system then searches for functions with :path metadata when the add-bindgins-as-routes function is called. The choice to use tags to define the Content-Type is not something the user can decide on their own. This leads to the need to return a hiccup-style data structure that will be processed by spork/htmlgen, rather than allowing the user to build the HTML themselves or use a different template system. The HTTP response code is set through the setdyn call, making it seem like setting a global variable.

The route functions take two parameters: request and post-data. The request is a general HTTP Request object, while post-data is nil unless the user sent a POST request, in which case it is decoded into a Janet table. The :render-mime can be set to application/json to easily transform any basic Janet data structures into JSON. However, HTTPF is basic and has significant limitations. The author points out that while it covers common web framework parts, it's not something you can rely on for beyond basic usage.

Other options in the Janet ecosystem include Circlet, which is licensed under the GNU GPL, and Joy, which is more full-featured but has issues with setting cookies. Overall, the HTTPF system is a good starting point for building a web application in Janet, but it's not an ideal solution for more complex applications.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at nick.gs →

More in Tech

gRPC Explained: APIs That Speak in Binary

A shop dashboard needs one thing from the orders service: the details of order 1042. Over plain JSON the request is easy to write and easy to break.

  • gRPC is a protocol for building APIs that communicate in binary format.
  • It uses a .proto file contract to define services, methods, and messages.
  • gRPC operates over HTTP/2, enabling streaming and shared connections.

🎃 The Real Nightmare Isn't a Bug. It's a Bug Nobody Notices. 🎃

Imagine deploying a new feature. All tests pass. CI is green. No errors in the logs. Everything looks fine. Then a user reports that their payment was processed twice.

  • Real nightmare in software dev is unnoticed bugs
  • Payment double charge due to lost response
  • Idempotency key can prevent double charges

More from Saturday 7 November →