Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jchavarri/ocaml_webapp
A minimal example of a lightweight webapp in OCaml
https://github.com/jchavarri/ocaml_webapp
ocaml reasonml web-application webapp
Last synced: 2 months ago
JSON representation
A minimal example of a lightweight webapp in OCaml
- Host: GitHub
- URL: https://github.com/jchavarri/ocaml_webapp
- Owner: jchavarri
- License: mit
- Created: 2020-07-19T09:48:51.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-13T11:54:26.000Z (about 2 years ago)
- Last Synced: 2024-10-15T02:34:20.870Z (2 months ago)
- Topics: ocaml, reasonml, web-application, webapp
- Language: Reason
- Homepage: https://ocaml-webapp.herokuapp.com/
- Size: 1.39 MB
- Stars: 45
- Watchers: 3
- Forks: 2
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - ocaml_webapp
README
# ocaml_webapp
A minimal example of a lightweight webapp in OCaml.
It features a possible organization of files to maximize code sharing between server (native OCaml) and client (BuckleScript). Some of the things shared are:
- React components, which are server-side rendered with [Tyxml](https://github.com/ocsigen/tyxml) and hydrated with [ReasonReact](https://reasonml.github.io/reason-react/)
- Routes, through the OCaml library [Routes](https://github.com/anuragsoni/routes).
- API endpoints interface types, through library [ATD](https://github.com/ahrefs/atd), that also generates encoders / decoders automatically.Potentially, `shared` folder can contain other shared code like validation functions, data processing, etc.
### Getting started
Create an opam local switch:
```bash
make create-switch
```Install `dune` in the newly created switch:
```bash
opam install dune
```Install all dependencies:
```bash
make deps
```Build client:
```
yarn webpack:dev
```Build and run the server:
```bash
make run
```Open the browser and go to http://localhost:3000/.
It's also possible to get hot reloading while developing. For that, start the server (to be able to serve API requests) with `make run`, run BuckleScript in `yarn start` and then start Webpack dev server with `yarn server`.
### Run databases locally
```
docker-compose -f docker-compose.dev.yml up -d
```### Deploying to Heroku
Right now, the example allows to easily deploy the app to Heroku. Build times are longer than they should, but hopefully
this will be fixed [soon](https://github.com/jchavarri/ocaml_webapp/issues/1).- Install the Heroku CLI: http://toolbelt.heroku.com/
- Run `heroku create your_app` from the app folder
- Set stack for the app to `container`: `heroku stack:set container`
- `git push heroku master`### Resources
- Amazing tutorial to create a lightweight OCaml webapp: https://shonfeder.gitlab.io/ocaml_webapp/
- Deploying native Reason/OCaml with Zeit's now.sh: https://jaredforsyth.com/posts/deploying-native-reason-ocaml-with-now-sh/
- Deploying OCaml server on Heroku: https://medium.com/@aleksandrasays/deploying-ocaml-server-on-heroku-f91dcac11f11