- Creating a ReasonML Native App: Installing, Editing, Configuring
- Creating a ReasonML Native App: Building and Running
- Creating a ReasonML Native App: Command Line Arguments
- Creating a ReasonML Native App: Configuration Files
- Creating a ReasonML Native App: Curses Terminal Interface
- Creating a ReasonML Native App: Python Plugins
- Creating a ReasonML Native App: Files I/Os
- Creating a ReasonML Native App: Native Promises
- Creating a ReasonML Native App: Web Requests
- Creating a ReasonML Native App: Shell Commands
- Creating a ReasonML Native App: Handling CSV Files
- Creating a ReasonML Native App: Native JSON Handling
- Creating a ReasonML Native App: Memoizing DNS queries
This means that if you wish to create a “native” application, it seems that you are expected to rely on
Node and Electron. And that’s a shame, because OCaml itself provides a very competent native compiler and we are going to use it. I hope I can remember all the hoops I had to jump through so that you don’t have to.
This is, hopefully, the first of a series of blog posts I will write over a few weeks to make it easier for anyone else to start using ReasonML natively.
I will show you how I created an application that provides an easy way to check that a web site — especially a single page application (‘SPA’) — reliably sends the same replies to the same queries, thus avoiding regressions due to new features being added or old issues being addressed.
This application needs to be fast and multi platforms.
You favorite web browser likely provides a way to generate a HAR file, and we are going to leverage this file. A .har file contains, in json format, a list of all HTTP queries and the website’s responses.
For instance, in Chrome:
- Open a tab to the page you are planning on automating
- Open the developer console (on MacOS: ⌘ Opt i ) and click [ ] Preserve log
- Navigate to the Network tab
- Perform all desired interactions with the web page/application
- When done, right-click anywhere in the now sizable list of network events
- Select Save as HAR with content and save with a memorable name.
This was step #1. Step #2 consists of running our application (“reasonable fidelity”) and make sure that it is happy.
So, what will we learn?
- Installing Reason and OCaml
- Configuring our favorite editor as an IDE
- Configuring a native application
- Building and running a native application
- Handling command line arguments
- Reading configuration files
- Creating an interactive terminal interface using NCurses
- Wiring in Python plugins
- Native File I/Os
- Native Promises
- Web Requests, posting, cookies and tokens
- Invoking the Shell
- Exporting to CSV[?]
- Memoizing DNS queries
Yes, there’s a – very – short version:
- OCaml – and its vast library – is your (not-at-all) secret weapon: after all, Reason lives on top of OCaml!
Don’t panic! If you are not all that familiar with OCaml’s syntax, Reason comes with an excellent tool called
refmt which allows you to translate OCaml code to Reason.
Keep in mind that, target-wise, native compiling and using BuckleScript do not intersect:
(Refresh if the diagram below doesn’t display properly)