Giter Club home page Giter Club logo

re-web's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.