# How suitable is OCaml for full stack web development?

**URL:** <https://discuss.ocaml.org/t/how-suitable-is-ocaml-for-full-stack-web-development/12879>\
**Category:** Learning\
**Created:** [August 21, 2023, 10:51pm UTC](https://discuss.ocaml.org/t/how-suitable-is-ocaml-for-full-stack-web-development/12879 "2023-08-21T22:51:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bememol](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@bememol](https://discuss.ocaml.org/u/bememol)\
**Post date:** [August 21, 2023, 10:51pm UTC](https://discuss.ocaml.org/t/how-suitable-is-ocaml-for-full-stack-web-development/12879/1 "2023-08-21T22:51:49Z")

</div>

I’m looking into getting more into a full stack web development. I do lots and lots of backend services but I really would like to cross the region to the frontend as well and I would like to avoid as much JS as possible. Htmx caught my attention but I still need some frontend code for more dynamic parts of my webapp. This can be pure JS or wasm. How does OCaml perform at this kind of situation? My ideal scenario would be something like OCaml + Htmx for most pages and at some pages some kind of compilation to JS or wasm for the dynamic parts.

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [August 22, 2023, 5:18am UTC](https://discuss.ocaml.org/t/how-suitable-is-ocaml-for-full-stack-web-development/12879/2 "2023-08-22T05:18:20Z")

</div>

I recommend checking out my library to write HTM especially as it ships with the htmx attributes out of the box: [GitHub - yawaramin/dream-html: Generate HTML markup from your OCaml Dream backend server](https://github.com/yawaramin/dream-html)

If you want to compile to JS, there are a couple of options. The first and simplest one you should probably look at is ReScript. It’s an OCaml derivative that has been modified to look more like TypeScript while keeping the compile speed and type safety of OCaml. There are a couple of other options but I’ll let others give details about those.

Lastly, for slightly more client-side interaction than what htmx does, check out AlpineJS, which is a library which uses attributes similar to htmx but is frontend only. It can probably give you a lot more functionality with very little custom-written JS.

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [August 22, 2023, 7:46am UTC](https://discuss.ocaml.org/t/how-suitable-is-ocaml-for-full-stack-web-development/12879/3 "2023-08-22T07:46:00Z")

</div>

> [@yawaramin](#):
>
> The first and simplest one you should probably look at is ReScript.

Well if you want to do full stack development in OCaml you probably don’t want to add yet _another_ language. So the “first and simplest” would rather be to use: [js\_of\_ocaml](http://ocsigen.org/js_of_ocaml/latest/manual/overview) which is a very stable and funded OCaml to JavaScript compiler closely following the latest compiler developments.

However if you don’t want to lose your time I’d personally advise to steer away from js\_of\_ocaml FFI and browser APIs and use [`brr`](https://erratique.ch/software/brr) instead which is an order of magnitude more ergonomic and documented. But I’m biased.

Also if you want to get an idea on how that could look like you can have a look [here](https://github.com/dbuenzli/hyperbib) (though I’m not happy with all the way the code looks like there :-). This is a fully working and actively used application that closely matches the description of what you are after. It’s a basic CRUD app not using `htmx` but a [derivative](https://erratique.ch/software/htmlact) that tries to address some of its [shortcomings](https://discuss.ocaml.org/t/htmx-htmlact-web-development-approach/9993/8), along with a little tiny bit of custom front end code. Though they will eventually be, not every library I’m using there is formally distributed yet, so you may have to use other components but it can give you an idea.

---

<div class="post-metadata">

**Author:** ![Vincent\_Balat](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vincent_balat/32/2191_2.png) [@Vincent\_Balat](https://discuss.ocaml.org/u/Vincent_Balat)\
**Post date:** [August 22, 2023, 8:52am UTC](https://discuss.ocaml.org/t/how-suitable-is-ocaml-for-full-stack-web-development/12879/4 "2023-08-22T08:52:45Z")

</div>

The Ocsigen project provides a full set of tools for full stack Web development, among which:

- [Js\_of\_ocaml](https://ocsigen.org/js_of_ocaml), a compiler from OCaml to JS
- [Eliom](https://ocsigen.org/eliom), a 100% full stack Web framework (traditional Web programming + integrated client/server programming, generation of pages either on server or client, mobile apps for Android and iOS)
- [Ocsigen Toolkit](https://ocsigen.org/ocsigen-toolkit), a set of client-server widgets for Web and mobile applications

The project is mature and used by real world applications (especially [Be Sport](https://besport.com/news)).

You can find the main documentation [here](https://ocsigen.org/tuto/latest/manual/basics)

---

<div class="post-metadata">

**Author:** ![xvw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/xvw/32/2041_2.png) [@xvw](https://discuss.ocaml.org/u/xvw)\
**Post date:** [August 22, 2023, 10:07am UTC](https://discuss.ocaml.org/t/how-suitable-is-ocaml-for-full-stack-web-development/12879/5 "2023-08-22T10:07:14Z")

</div>

And, a little shameless plug, we are currently developing a minimalist solution (based on several proven building blocks from the OCaml community) for building web applications with OCaml, easily:

- [GitHub - funkywork/nightmare: A set of components that fit, a priori, relatively well with the web framework (OCaml) Dream to try to build, at best, and quickly, dynamic web applications.](https://github.com/funkywork/nightmare)  
which covers the backend (currently, above Dream) and the frontend (above Js\_of\_ocaml and an overlay to OCaml-vdom and Tyxml) which allows you to quickly create APIs and clients (we are currently working on the abstraction of forms)
- [GitHub - funkywork/yourbones: A companion library for writing applications on Tezos (in OCaml)](https://github.com/funkywork/yourbones)  
Even if it’s not entirely related to web development, blockchains can act as a 4th tier, and this library (WIP) works well with Nightmare to interact with Tezos ([example](https://github.com/funkywork/tezos-dapps-examples)).

Last year, we developed a forum in OCaml: [GitHub - xvw/muhokama: A simple forum built on top of Dream, Caqti, Omd, Preface, Cmdliner and other useful OCaml libraries](https://github.com/xvw/muhokama) which proves that OCaml is perfectly suited to web development, and the proposals made by my predecessors show that in addition to being suited, OCaml is **effective** (I know of few frameworks as ambitious as Ocsigen for example, which at the time and still today is particularly revolutionary).

---

<div class="post-metadata">

**Author:** ![psb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/psb/32/4549_2.png) [@psb](https://discuss.ocaml.org/u/psb)\
**Post date:** [August 22, 2023, 11:07am UTC](https://discuss.ocaml.org/t/how-suitable-is-ocaml-for-full-stack-web-development/12879/6 "2023-08-22T11:07:36Z")

</div>

Have a look at Reason, ReasonReact and Melange: [ReasonReact is back (and powered by Melange) · ReasonReact](https://reasonml.github.io/reason-react/blog/2023/06/11/reborn)

Ahrefs is built with Melange: [https://medium.com/ahrefs/ahrefs-is-now-built-with-melange-b14f5ec56df4](https://medium.com/ahrefs/ahrefs-is-now-built-with-melange-b14f5ec56df4)
