• Stars
    star
    263
  • Rank 155,624 (Top 4 %)
  • Language
    OCaml
  • License
    MIT License
  • Created almost 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Experimental web framework for ReasonML & OCaml

ReWeb - a type-safe ergonomic ReasonML and OCaml web framework (WIP)

npm Build Status Test Status

ReWeb is a web framework based on several foundations:

  • The amazing work of the people behind Httpaf, H2, Esy, and others
  • The core idea of 'Your server as a function' by Marius Eriksen which was also the idea behind Twitter's Finagle web stack
  • Jasim Basheer's essay 'Rails on OCaml' which identifies the need for an ergonomic, Rails-like web framework that still preserves the type safety benefits of OCaml.

ReWeb's main concepts are:

  • Services: a service is a function from a request to a promise of response (i.e. an asynchronous function).
  • Filters: a filter is a function that takes a service as input and returns a service as output. It can be inserted into the 'request pipeline' and manipulate the request before the service finally handles it.
  • Server: a server is a function that takes a route (pair of HTTP method and path list) as input and returns a service as output.
  • Type-safe request pipeline: requests have a type parameter that reveals their 'context' i.e. some data that's stored inside them. Filters and services must change requests correctly and in the right order, or the compiler will present type errors.

Notice that all the main concepts here are just functions. They are all composeable using just function composition. Services can call other services. Filters can slot together by calling each other. Servers can delegate smaller scopes to other servers. See bin/Main.re for examples of all of these.

Documentation

Examples

Fullstack Reason

Check out the demo repo which shows a fullstack Reason setup with ReWeb and ReasonReact, with code sharing: https://github.com/yawaramin/fullstack-reason/

This repo can be cloned and used right away for a new project.

Bin directory

Finally, check out the example server in the bin/ directory. The Main.re file there has extensive examples of almost everything ReWeb currently supports.

Run the example server:

$ esy bin

Send some requests to it:

$ curl localhost:8080/hello
$ curl localhost:8080/auth/hello
$ curl --user 'bob:secret' localhost:8080/auth/hello

Go to http://localhost:8080/login in your browser, etc.

Try

You need Esy, you can install the beta using npm:

$ npm install --global esy@latest

Then run the esy command from this project root to install and build dependencies.

$ esy

Now you can run your editor within the environment (which also includes merlin):

$ esy $EDITOR
$ esy vim

Alternatively you can try vim-reasonml which loads esy project environments automatically.

After you make some changes to source code, you can re-run project's build again with the same simple esy command.

$ esy

Generate documentation:

$ esy doc
$ esy open '#{self.target_dir}/default/_doc/_html/index.html'

Shell into environment:

$ esy shell

Run the test suite with:

$ esy test

Warning

ReWeb is experimental and not for production use! I am still ironing out the API. But (imho) it looks promising for real-world usage.

More Repositories

1

fullstack-reason

A demo project that shows a fullstack ReasonML/OCaml appโ€“native binary + webapp
Reason
166
star
2

scala-modules

Experimental implementations of ML-style modules in Scala
Scala
142
star
3

bucklescript-bindings-cookbook

Task-oriented guide to writing JavaScript bindings for BuckleScript
115
star
4

prometo

A type-safe JavaScript promise library for ReasonML
Reason
31
star
5

fsharp-typeclasses

F#
24
star
6

ggspec

A lightweight, functional-style unit testing framework for Guile/Scheme
Scheme
24
star
7

re-hyperapp

Almost zero-cost bindings for the https://github.com/hyperapp/hyperapp UI library.
OCaml
21
star
8

ocaml_sql_query

PoC of functional-style SQL query
OCaml
21
star
9

ocaml-decimal

Arbitrary-precision floating-point decimals
OCaml
21
star
10

lambdak

Full anonymous functions for Python
Python
19
star
11

dbc

Design-by-contract programming for JavaScript and ReasonML
OCaml
12
star
12

bs-webapi

(WIP) BuckleScript Web API Bindings
OCaml
10
star
13

stubbex

Stub and validate HTTP endpoints with ease.
Elixir
10
star
14

bs-hyperapp

DEPRECATED - see https://github.com/yawaramin/re-hyperapp for a more recent (experimental) attempt
OCaml
8
star
15

dream-html

Generate HTML markup from your Dream backend server
OCaml
6
star
16

bucklescript-cyclejs-test

OCaml
5
star
17

resilient-services

OCaml
5
star
18

learning-tydd-reason

Learning Type-Driven Development with ReasonML
OCaml
5
star
19

reason-workshop

HTML
4
star
20

aoc2020

Advent of Code 2020
OCaml
3
star
21

bs-pouchdb

OCaml
3
star
22

fake-io

A demonstration of controlling and testing the IO effect in Scala
Scala
3
star
23

fsharp-typed-json

JSON for F# using typeclasses.
F#
1
star
24

TDDMoney

My C# interpretation of the `Money' example from Kent Beck's Test-Driven Development by Example
C#
1
star
25

bs-doc-mgr

OCaml
1
star
26

fsharp-cond

Multi-Way Conditional Expression for F#
F#
1
star
27

lightweght-static-capabilities

Paper summary slides. Video:
OCaml
1
star
28

webagent

HTTP request builder using FreePascal/Lazarus
Pascal
1
star
29

letops

OCaml standard library let operators
OCaml
1
star
30

TDDUnit

My interpretation in C# of the unit-testing framework example from Kent Beck's Test-Driven Development
C#
1
star