Is OCaml Web yet?

Yes, but some parts are still missing

OCaml, traditionally known for its strength in systems programming, formal verification, and as the language of choice for numerous academic endeavors, is steadily maturing in the Web development landscape. With its strong static typing, emphasis on immutability, and excellent performance, it is gradually making a case for itself as a viable alternative to mainstream Web development languages.

The Web in OCaml is fast and type-safe! According to your needs, you can choose to use tidy server-side Web frameworks, or innovative full-stack solutions for integrated Web and mobile applications. To run in the browser, OCaml compiles to JavaScript and WebAssembly!

As a matter of fact, OCaml is used to power production Web systems, like Ahrefs, or the Be Sport social network.

If you're considering using OCaml for your next Web application, you should be aware that you might have to write a noticeable amount of things yourself and won't yet get an equivalent of all the features you may be used to coming from other languages. In particular, OCaml doesn't have out-of-the-box solutions for authentication or a fully production-ready query-builder. You'll also probably have some challenges if you need to interact with external services or external APIs.

However, this is often more than offset by the time you save thanks to the advantages of the language and the power of certain tools. The language's powerful type system will save you a lot of debugging time by eliminating many problems at compile time (such as html conformity). Innovative solutions such as multi-tier programming can drastically simplify client-server communication. Last but not least, OCaml can even allow you to program your Web and mobile application in a single code.

Want to Help?

Here are some projects that would help make OCaml a stronger candidate for Web applications:

  • Improve ocaml-swagger to be able to generate API for popular Web APIs like Stripe.
  • Implement a converter from JSON Schema to ATD. This would allow generating OCaml serializers for data formats that provide a JSON Schema (a lot of them do!).
  • Create an Oauth2 client library.
  • Create clients to the Azure services APIs.
  • 🟢 : stable, tested and mature
  • 🟡 : getting there, stable but still maturing
  • 🟠 : not yet stable, but progressing
  • 🔴 : unstable/incomplete, needs work
  • 🆘 : barely there, needs serious work


🟡 Web Frameworks

Web development frameworks for building OCaml Web applications.

  • dream Tidy, feature-complete Web framework
  • eliom Advanced client/server Web and mobile framework
  • opium OCaml web framework
  • sihl The Sihl web framework
  • ocsigen-start Higher-level library for developing Web and mobile applications with users, registration, notifications, etc

🟢 Browser

OCaml has excellent support for running in the browser! The Js_of_ocaml compiler, which translates OCaml into JavaScript, is a well-established tool dating back to 2010. It integrates seamlessly with the existing OCaml ecosystem and powers numerous production applications.

In addition, Melange is a more recent entry to the OCaml-JavaScript compiler space. Originating as a fork of ReScript, Melange may not have the extensive track record of Js_of_ocaml, but it builds on a very strong foundation and already integrates well with Dune, the OCaml build system.

  • js_of_ocaml Compiler from OCaml bytecode to JavaScript
  • melange Toolchain to produce JS from Reason/OCaml
  • brr Browser programming toolkit for OCaml
  • gen_js_api Easy OCaml bindings for JavaScript libraries
  • ts2ocaml Generate OCaml bindings from TypeScript definitions via the TypeScript compiler API
  • ocsigen-toolkit Reusable UI components for Eliom applications (client only, or client-server)
  • bonsai A library for building dynamic webapps, using Js_of_ocaml
  • ocaml-vdom This is a transition package, ocaml-vdom is now named vdom. Use the vdom package instead
  • fmlib_browser Write web applications for the browser in elm style

🟡 WebAssembly

Packages and tools for compiling OCaml code to WebAssembly.

  • wasm_of_ocaml Compiler from OCaml bytecode to WebAssembly
  • wasocaml Compiler from OCaml to WebAssembly
  • wasm Library to read and write WebAssembly (Wasm) files and manipulate their AST
  • owi OCaml toolchain to work with WebAssembly, including and interpreter

🟡 Lower Web-Stack

Packages that provide foundational networking and communication capabilities.

  • cohttp An OCaml library for HTTP clients and servers
  • httpaf A high-performance, memory-efficient, and scalable web server for OCaml
  • http Type definitions of HTTP essentials
  • ocsigenserver A full-featured and extensible Web server
  • tls Transport Layer Security purely in OCaml
  • websocket Websocket library
  • websocketaf Websocket implementation for use with http/af
  • gluten A reusable runtime library for network protocols
  • awa SSH implementation in OCaml
  • uri An RFC3986 URI/URL parsing library
  • dns An opinionated Domain Name System (DNS) library
  • tcpip OCaml TCP/IP networking stack, used in MirageOS
  • charrua DHCP wire frame encoder and decoder
  • mirage-nat Mirage-nat is a library for network address translation to be used with MirageOS
  • arp Address Resolution Protocol purely in OCaml
  • ethernet OCaml Ethernet (IEEE 802.3) layer, used in MirageOS
  • paf HTTP/AF and MirageOS
  • mimic A simple protocol dispatcher
  • tiny_httpd Minimal HTTP server using threads

🔴 HTTP Clients

HTTP client libraries for making HTTP requests.

  • cohttp An OCaml library for HTTP clients and servers
  • hyper Web client with HTTP/1, HTTP/2, TLS, and WebSocket support
  • ocurl Bindings to libcurl
  • http-lwt-client A simple HTTP client using http/af, h2, and lwt
  • ezcurl Friendly wrapper around OCurl

🟡 Templating

Packages that assist in generating dynamic HTML or text content.

  • tyxml A library for building correct HTML and SVG documents
  • embedded_ocaml_templates EML is a simple templating language that lets you generate text with plain OCaml
  • dream_html
  • ppx_dream_eml PPX to process Dream's Embedded ML syntax
  • mustache Mustache logic-less templates in OCaml
  • jingoo Template engine almost compatible with Jinja2(python template engine)

🟡 Static Site Generation

Packages for generating static websites.

  • finch Simple and fast site generator
  • stone Simple static website generator, useful for a portfolio or documentation pages
  • camyll A static site generator
  • yocaml YOCaml is a static site generator, mostly written in OCaml
  • dream-serve Static HTML website server with live reload
  • soupault Static website generator based on HTML rewriting
  • html_of_wiki Static website generator for software projects

🟡 Mobile apps

Packages for creating mobile applications

🔴 Authentication

Packages for authentication-related functionality in OCaml Web applications.

  • jwt Implementation of JWT in OCaml.
  • cookie Cookie handling for OCaml and ReasonML
  • FPauth Easy authentication system for Dream framework
  • u2f Universal Second Factor (U2F) implementation in OCaml
  • webauthn WebAuthn - authenticating users to services using public key cryptography
  • ssl Bindings for OpenSSL
  • twostep HOTP and TOTP algorithms for 2-step verification (for OCaml)
  • oidc Base package for working with OIDC
  • spoke SPAKE+EE implementation in OCaml

🟡 Binary protocols

There are implementations for a lot of popular protocols, some of them are solid, but some of them are still incomplete and need more testing. Some useful protocols for which there is no package include FlatBuffers and AMQP.

  • asn1-combinators Embed typed ASN.1 grammars in OCaml
  • avro Runtime library for encoding/decoding Avro
  • capnp OCaml code generation plugin for the Cap'n Proto serialization framework
  • grpc A modular gRPC library
  • protobuf Protobuf implementation for Ocaml
  • rpc A library to deal with RPCs in OCaml - meta-package
  • jsonrpc Jsonrpc protocol implemenation
  • thrift OCaml bindings for the Apache Thrift RPC system
  • bson A bson data structure, including encoding/decoding
  • cbor CBOR encoder/decoder (RFC 7049) - native OCaml implementation
  • mqtt OCaml MQTT client
  • msgpck Fast MessagePack ( library

🟠 Database

Database-related packages for interacting with databases in OCaml Web applications, from simple connectors to type-safe SQL wrappers.

  • petrol Petrol's an OCaml SQL API made to go FAST
  • caqti Unified interface to relational database libraries
  • pgocaml Native OCaml interface to PostgreSQL databases
  • sqlite3 SQLite3 bindings for OCaml
  • lmdb Bindings for LMDB, a fast in-file database with ACID transactions
  • irmin Irmin, a distributed database that follows the same design principles as Git
  • mysql Bindings to C client library for interacting with Mysql/MariaDB/Percona databases
  • postgresql Bindings to the PostgreSQL library
  • aws-rds Amazon Web Services SDK bindings to Amazon Relational Database Service
  • sequoia Type-safe query builder for OCaml
  • sqlgg SQL Guided (code) Generator
  • mariadb OCaml bindings for MariaDB

🆘 Internationalization

Internationalization and localization for OCaml applications.

  • gettext Internationalization library (i18n)
  • ocsigen-i18n I18n made easy for web sites written with eliom

🆘 Message Queues & Key-Value Stores

Packages for interacting with popular message queues and key-value stores.

  • amqp-client Amqp client base library
  • kafka OCaml bindings for Kafka
  • redis Redis client
  • zmq OCaml bindings for ZeroMQ 4.x

🟡 Serializers

Packages for serializing and deserializing data in different formats.

  • atd Parser for the ATD data format description language
  • yojson Yojson is an optimized parsing and printing library for the JSON format
  • jsonm Non-blocking streaming JSON codec for OCaml
  • sexplib Library for serializing OCaml values to and from S-expressions
  • yaml Parse and generate YAML 1.1/1.2 files
  • csv A pure OCaml library to read and write CSV files
  • bencode Bencode (`.torrent` file format) reader/writer in OCaml
  • toml Library for TOML with a parser, a serializer and a printer
  • xml-light Xml-Light is a minimal XML parser & printer for OCaml
  • graphql Build GraphQL schemas and execute queries against them
  • omd A Markdown frontend in pure OCaml
  • cmarkit CommonMark parser and renderer for OCaml
  • css CSS parser and printer
  • csexp Parsing and printing of S-expressions in Canonical form
  • data-encoding Library of JSON and binary encoding combinators

🟡 Syndication/RSS

Packages for syndicating content and working with RSS feeds.

  • syndic RSS1, RSS2, Atom and OPML1 parsing
  • river RSS2 and Atom feed aggregator for OCaml
  • rss Library to read and write RSS files

🆘 External Web APIs

Packages that provide OCaml bindings and clients for interacting with external Web APIs.

🟠 Logging

Packages for logging and monitoring that assist in tracking application behavior and performance.

  • logs Logging infrastructure for OCaml
  • dolog The dumb OCaml logging library
  • tracing Tracing library
  • catapult Tracing system based on the Catapult/TEF format
  • opentelemetry Instrumentation for
  • prometheus Client library for Prometheus monitoring

🟠 Email

Packages for sending and managing email communications.

  • tidy_email An OCaml library that simplifies connecting to email services
  • emile Parser of email address according RFC822
  • smtp SMTP library with Unix and Lwt backends
  • letters Client library for sending emails over SMTP
  • mrmime Mr. MIME
  • sendmail Implementation of the sendmail command
  • received Received field according RFC5321
  • email_message E-mail message parser
  • colombe SMTP protocol in OCaml
  • dkim Implementation of DKIM in OCaml
  • uspf SPF implementation in OCaml

🟡 Compression

Packages that enable compression and decompression of data in OCaml Web applications.

  • zlib Bindings to the zlib compression library
  • decompress Implementation of Zlib and GZip in OCaml
  • camlzip Accessing compressed files in ZIP, GZIP and JAR format
  • lz4 Bindings to the LZ4 compression algorithm
  • ezgzip Simple gzip (de)compression library
  • hpack An HPACK (Header Compression for HTTP/2) implementation in OCaml
  • brotli Bindings to Google's Brotli compresion algorithm
  • zstd Bindings to zstd compression library
  • snappy Bindings to snappy - fast compression/decompression library
  • lzo Bindings to LZO - a portable lossless data compression library
  • zstandard OCaml bindings to Zstandard
  • carton Implementation of PACKv2 file in OCaml

🟡 Cryptography

Packages for secure communication, encryption, hashing, and other cryptographic operations.

  • cryptokit A library of cryptographic primitives
  • mirage-crypto Simple symmetric cryptography for the modern age
  • nocrypto Simpler crypto
  • pkcs11 PKCS#11 OCaml types
  • tls Transport Layer Security purely in OCaml
  • x509 Public Key Infrastructure (RFC 5280, PKCS) purely in OCaml
  • fiat-p256 Primitives for Elliptic Curve Cryptography taken from Fiat
  • sha Binding to the SHA cryptographic functions
  • blake2 Blake2 cryptography
  • blake3 Blake3 cryptography
  • bls12-381 Implementation of the BLS12-381 curve (wrapper for the Blst library)
  • pbkdf Password based key derivation functions (PBKDF) from PKCS#5
  • dirsp-proscript OCaml-ified interfaces for the ProScript Cryptography Library
  • digestif Hashes implementations (SHA*, RIPEMD160, BLAKE2* and MD5)

🟠 En- & Decoding

Encoding and decoding various data formats.

  • tar Decode and encode tar format files in pure OCaml
  • imagelib Library implementing parsing of image formats such as PNG, BMP, PPM
  • base64 Base64 encoding for OCaml
  • multipart-form-data Parser for multipart/form-data (RFC2388)
  • multipart_form Multipart-form: RFC2183, RFC2388 & RFC7578
  • biniou Binary data format designed for speed, safety, ease of use and backward compatibility as protocols evolve

Help Improve Our Documentation

All OCaml docs are open source. See something that's wrong or unclear? Submit a pull request.