1. Dream: The Modern Web Workhorse
If you're looking for a batteries-included web framework that feels current and comprehensive, Dream is your answer. It's built from the ground up with modern OCaml features, including first-class support for promises (Lwt) for clean asynchronous code.
Dream handles everything from routing and middleware to WebSockets and GraphQL, making it a powerful choice for building complex web services and applications. What makes it pair so well with OCaml is its emphasis on security and type safety. It provides built-in CSRF protection and a templating engine that helps prevent cross-site scripting (XSS) attacks by construction. For developers coming from Express.js or Django, Dream offers a familiar structure with the added benefits of OCaml's robust type system.
2. Opium: The Minimalist API Builder
Not every project needs a full-stack framework. For building fast, lightweight web services and APIs, Opium is a standout. Inspired by minimalist frameworks like Ruby's Sinatra, Opium gives you the essentials—routing, requests, and responses—and gets out of your way. This minimalist philosophy makes it incredibly flexible. You compose your application from small, independent middleware components, which fits perfectly with OCaml's functional approach. Its small surface area means it’s easy to learn and reason about. Opium is an excellent choice when performance is critical and you want full control over your application's architecture without the overhead of a larger framework.
3. ReScript: For Type-Safe JavaScript Front-Ends
While not a traditional OCaml framework, ReScript is a vital part of the ecosystem for front-end development. ReScript is a language that compiles to highly readable and performant JavaScript, but its syntax and type system are derived directly from OCaml. This allows you to build complex front-end applications, especially with its world-class React bindings (ReScriptReact), while enjoying OCaml's powerful type inference and soundness. It effectively lets you write OCaml-style code that runs in the browser. By pairing a ReScript front-end with an OCaml back-end (perhaps built with Dream), you can achieve end-to-end type safety, sharing types between the client and server for an incredibly robust development experience.
4. Js_of_ocaml + Brr: The Direct-to-Browser Approach
For those who want to use OCaml on the front-end without an intermediary language like ReScript, the combination of `js_of_ocaml` and the `Brr` library is the standard. `Js_of_ocaml` (JSOO) is a compiler that translates OCaml bytecode into JavaScript. It provides a more direct mapping, allowing you to use a vast amount of existing OCaml libraries in the browser. The `Brr` library then provides a clean, functional, and type-safe set of bindings for interacting with browser APIs—manipulating the DOM, handling events, and making network requests. This pairing is for developers who love OCaml's syntax and ecosystem and want to bring its full power to client-side development with minimal compromise.
5. TyXML: For Statically-Typed HTML
TyXML isn't a web framework on its own, but it's an essential library that pairs beautifully with back-end frameworks like Dream and Opium. Its purpose is simple but profound: it allows you to generate HTML and SVG using OCaml's type system. This means that invalid HTML—like mismatched tags or incorrect attributes—becomes a compile-time error, not a run-time bug. By constructing your views with TyXML, you eliminate an entire class of front-end rendering errors. It encourages a declarative, component-based approach to building user interfaces that feels natural in a functional language. It's the perfect companion for ensuring your server-rendered HTML is always correct.
6. Cmdliner: For Declarative Command-Line Interfaces
Not all applications are web-based. OCaml is fantastic for building high-performance command-line tools, and Cmdliner is the go-to framework for this. It provides a declarative way to define your CLI's arguments, flags, and subcommands. You simply describe the terms and their types, and Cmdliner automatically handles parsing, validation, and generating help messages (`--help`). This approach separates the logic of your CLI from the core application logic, leading to cleaner, more maintainable code. The way it uses OCaml's functors and modules to build up complex command structures is a masterclass in leveraging the language's features, making it a joy to work with.
7. Ocsigen: The Multi-Tier Pioneer
Ocsigen is one of the oldest and most ambitious frameworks in the OCaml ecosystem. Its core idea is to enable multi-tier programming, where you can write client and server code in the same file, and the framework figures out where each piece should run. It has its own powerful extensions to OCaml to facilitate this, and it compiles to both native server code and JavaScript for the client. While it has a steeper learning curve than frameworks like Dream, Ocsigen offers a unique, highly integrated development model for building complex, interactive web applications. It’s a testament to OCaml's flexibility and is still actively developed for projects that can benefit from its all-in-one philosophy.













