Reason Native Web
  • Guides
  • Help
  • GitHub

›Morph

Morph

  • Getting started
  • Simple switch-based router
  • A simple proxy using Morph_client
  • Usage with Routes library
  • Writing middlewares for Morph

JOSE

  • Getting started

OpenID Connect

  • Getting started

API Reference

  • API Reference

Getting started

Hello World!

To get started with your first web server simply call the start_server function with a handler function. The handler functions has the signature Request.t => Response.t. Where a Request.t is a record with everything you need from the underlying request and a Response.t is everything we need to create a response, status, headers and a body.

There are some helpers to create some of the common responses, we will use the text response for a "Hello World!" response.

Reason
OCaml
let server = Morph_server_http.make();
let handler = _request => Morph.Response.text("Hello World!");

Morph.start(~servers=[server], handler) |> Lwt_main.run;
let () =
let server = Morph_server_http.make () in
let handler _request =
Morph.Response.text "Hello World!" Morph.Response.empty in
Morph.start ~servers:[server] handler |> Lwt_main.run

The code above will answer every request with the text "Hello World!".

Congratulations you have now created your first Morph server running natively.

Pesy template

There is also a pesy template to help you get started quickly. If you don't have esy and pesy installed you can get them from npm with the following command:

npm install -g esy pesy@next

When you have installed them you can create a folder, cd into it and run the pesy command pointing to our template.

mkdir my_project
cd my_project
pesy --template=reason-native-web/morph-hello-world-pesy-template

You should now have a working project that you can play around with and even build on to get to production.

Simple switch-based router →
Reason Native Web
Docs
Your first web serverGuidesAPI Reference
Community
Reason DiscordReasonML ForumOCaml DiscordOCaml Discuss
More
GitHub
Copyright © 2019 Your Name or Your Company Name