Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bikallem/spring

Spring - A Delightful OCaml web programming library (unreleased)
https://github.com/bikallem/spring

Last synced: 3 months ago
JSON representation

Spring - A Delightful OCaml web programming library (unreleased)

Awesome Lists containing this project

README

        

# 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, .png` etc
- [x] HTTP/1.1 (RFC 9112) multicore/parallel server/client
- [x] HTTPS/1.1 server/client (TLS/1.3)
- [x] Closely aligned with `eio` io library

### Hello world in Spring [^1]
[^1]: See https://github.com/bikallem/spring/tree/main/examples/hello for full sample

```hello.ml```

```ocaml
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```

```html
Hello world!
```

```layout_v.ohtml```

```html
fun ~title ~body ->


@title


{{ body }}

```

```products_v.ohtml```

```html
open Spring

fun products ->


Hello
world!

Products for sale



    { List.iter (fun product ->

  1. @{if product = "apple" then "red apple" else product}

    @producthello
    @product


  2. ) products
    }


```