{"id":13726297,"url":"https://github.com/rgrinberg/opium","last_synced_at":"2025-05-15T02:06:36.730Z","repository":{"id":12485212,"uuid":"15154549","full_name":"rgrinberg/opium","owner":"rgrinberg","description":"Sinatra like web toolkit for OCaml","archived":false,"fork":false,"pushed_at":"2025-02-05T19:42:06.000Z","size":1193,"stargazers_count":774,"open_issues_count":34,"forks_count":70,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-14T13:58:27.284Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rgrinberg.png","metadata":{"files":{"readme":"README.cpp.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-13T04:13:35.000Z","updated_at":"2025-04-11T07:11:06.000Z","dependencies_parsed_at":"2025-02-16T14:10:28.147Z","dependency_job_id":"1458f128-ef8b-4411-a937-b306663304a5","html_url":"https://github.com/rgrinberg/opium","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgrinberg%2Fopium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgrinberg%2Fopium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgrinberg%2Fopium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgrinberg%2Fopium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rgrinberg","download_url":"https://codeload.github.com/rgrinberg/opium/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259370,"owners_count":22040819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:02:58.438Z","updated_at":"2025-05-15T02:06:36.694Z","avatar_url":"https://github.com/rgrinberg.png","language":"OCaml","readme":"Opium\n=====\n\nSince version 0.19.0, Opium uses httpaf. The last version that used Cohttp can be found at https://github.com/rgrinberg/opium/tree/0.18.0\n\n## Executive Summary\n\nSinatra like web toolkit for OCaml based on [httpaf](https://github.com/inhabitedtype/httpaf/) \u0026 [lwt](https://github.com/ocsigen/lwt)\n\n## Design Goals\n\n* Opium should be very small and easily learnable. A programmer should\nbe instantly productive when starting out.\n\n* Opium should be extensible using independently developed plugins. This is a\n_Rack_ inspired mechanism borrowed from Ruby. The middleware mechanism in\nOpium is called `Rock`.\n\n## Installation\n\n### Stable\n\nThe latest stable version is available on opam\n\n```\n$ opam install opium\n```\n\n### Master\n\n```\n$ opam pin add rock.~dev https://github.com/rgrinberg/opium.git\n$ opam pin add opium.~dev https://github.com/rgrinberg/opium.git\n```\n\n## Documentation\n\nFor the **API documentation**:\n\n- Read [the hosted documentation for the latest version][hosted-docs].\n- Build and view the docs for version installed locally using [`odig`][odig]:\n  `odig doc opium`.\n\nThe following **tutorials** walk through various usecases of Opium:\n\n- [A Lightweight OCaml Webapp Tutorial](https://shonfeder.gitlab.io/ocaml_webapp/)\n  covers a simple webapp generating dynamic HTML on the backend and\n  interfacing with PostgreSQL.\n\nFor **examples** of idiomatic usage, see the [./examples directory](./examples)\nand the simple examples below.\n\n[hosted-docs]: https://rgrinberg.github.io/opium/\n[odig]: https://github.com/b0-system/odig\n\n## Examples\n\nAssuming the necessary dependencies are installed, `$ dune build @example` will\ncompile all examples. The binaries are located in `_build/default/example/`.\n\nYou can execute these binaries directly, though in the examples below we use\n`dune exec` to run them.\n\n### Hello World\n\nHere's a simple hello world example to get your feet wet:\n\n`$ cat hello_world.ml`\n\n``` ocaml\n#include \"example/hello_world/main.ml\"\n```\n\ncompile and run with:\n\n```sh\n$ dune exec examples/hello_world.exe \u0026\n```\n\nthen call\n\n```sh\ncurl http://localhost:3000/person/john_doe/42\n```\n\nYou should see the greeting\n\n```json\n{\"name\":\"john_doe\",\"age\":42}\n```\n\n### Middleware\n\nThe two fundamental building blocks of opium are:\n\n* Handlers: `Request.t -\u003e Response.t Lwt.t`\n* Middleware: `Rock.Handler.t -\u003e Rock.Handler.t`\n\nAlmost all of opium's functionality is assembled through various\nmiddleware. For example: debugging, routing, serving static files,\netc. Creating middleware is usually the most natural way to extend an\nopium app.\n\nHere's how you'd create a simple middleware turning away everyone's\nfavourite browser.\n\n``` ocaml\n#include \"example/simple_middleware/main.ml\"\n```\n\nCompile with:\n\n```sh\n$ dune build example/simple_middleware/main.ml\n```\n\nHere we also use the ability of Opium to generate a cmdliner term to run your\napp. Run your executable with `-h` to see the options that are available to you.\nFor example:\n\n```\n# run in debug mode on port 9000\n$ dune exec dune build example/simple_middleware/main.exe -- -p 9000 -d\n```\n","funding_links":[],"categories":["OCaml","Libraries","Web Development","\u003ca name=\"OCaml\"\u003e\u003c/a\u003eOCaml"],"sub_categories":["Web Frameworks"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgrinberg%2Fopium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frgrinberg%2Fopium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgrinberg%2Fopium/lists"}