Spring
Spring - A Delightful OCaml web programming library (unreleased)
Install / Use
/learn @bikallem/SpringREADME
Spring
A Delightful OCaml web programming library.
Hightlights:
- [x]
ohtml- a fast, compiled view engine allowing you to mix HTML with OCaml code - [x] Type safe, radix-tree based url routing engine. Use ppx to specify route path, e.g.
[%r "/store/products/:int"] - [x] Form handling/data upload (multipart/formdata protocol - RFC 9110 - for standards compliance and interoperability)
- [x] CSRF form protection (Anti CSRF mechanism)
- [x] Secure HTTP session based on encrypted cookie
- [ ] Secure HTTP session based on SQLite/Postgres/Mysql
- [x] HTTP Cookies (RFC 6265)
- [x] Type-safe HTTP header manipulation
- [x] Fullly compliant (RFC 7230) HTTP chunked transfer protocol (both client and server)
- [x] HTTP file server - host/serve static web assets such as
.css, .js, .jpg, .pngetc - [x] HTTP/1.1 (RFC 9112) multicore/parallel server/client
- [x] HTTPS/1.1 server/client (TLS/1.3)
- [x] Closely aligned with
eioio library
Hello world in Spring [^1]
[^1]: See https://github.com/bikallem/spring/tree/main/examples/hello for full sample
hello.ml
open Spring
let say_hello _req = V.view ~title:"Hello Page" V.hello_v
let display_products _req =
V.products_v [ "apple"; "oranges"; "bananas" ]
|> V.view ~title:"Products Page"
let () =
Eio_main.run @@ fun env ->
Server.app_server ~on_error:raise env#clock env#net
|> Server.get [%r "/"] say_hello
|> Server.get [%r "/products"] display_products
|> Server.run_local ~port:8080
hello_v.ohtml
<span>Hello world!</span>
layout_v.ohtml
fun ~title ~body ->
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
</head>
<body>
{{ body }}
</body>
</html>
products_v.ohtml
open Spring
fun products ->
<div id=div1
class="abc ccc aaa"
disabled
{ Ohtml.attribute ~name:"hx-swap" ~value:"outerHTML" }
get=@{if true then "/products" else "/index"}
hx-sse=@"connect:/news_update">
Hello
<span>world!</span>
<h2>Products for sale</h2>
<ol>
{ List.iter (fun product ->
<li>
@{if product = "apple" then "red apple" else product}
<span>
@product<text>hello</text>
@product
</span>
</li>
) products
}
</ol>
</div>
Related Skills
node-connect
334.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
334.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.2kCommit, push, and open a PR
