Ambiorix logo Ambiorix logo Ambiorix
  • Home
  • Documentation
  • Blog
  • Showcase

On this page

  • Full stack, right in R
  • Features
  • Get Started

Ambiorix

Unopinionated, minimalist web framework for R inspired by express.js

Watch Video Read the docs

Full stack, right in R

Easily build web applications & APIs, all in one syntax and right in R.

Easy to use

Create applications with the tried and tested API of express.js

One syntax

Use a single syntax to build RESTful APIs and web applications

Extendable

Leverage existing middlewares, parsers & serializers or create your own

library(ambiorix)

app <- Ambiorix$new(port = 3000L)

app$get("/", function(req, res) {
  res$send("Hello, World!")
})

app$get("/api/v1/users", function(req, res) {
  users <- data.frame(
    uid = 1:3,
    firstname = c("Alice", "Bob", "Cate"),
    lastname = c("Queen", "Jeremy", "Reece"),
    active = c(TRUE, FALSE, TRUE)
  )

  res$json(users)
})

app$start()

Features

With Ambiorix, you get:

Routing

Build multipage applications right out of the box.

Templating

For Server-Side Rendering (SSR). HTML, markdown, pug, etc.

Middleware

Easily pre-process requests to the server.

Websockets

For when you need bi-directional communication between the server & client.

Async

Use asynchronous programming techniques by returning promises from request handlers.

Autonomy

You have absolute full control over the request-response cycle!

  • Routing
  • Templating
  • Middleware
  • Websockets
  • Async
library(ambiorix)

app <- Ambiorix$new(port = 3000L)

app$get("/", function(req, res) {
  res$send("Home!")
})

app$get("/about", function(req, res) {
  res$send("About me!")
})

app$get("/users/:id", function(req, res) {
  msg <- sprintf("This is user #%s", req$params$id)
  res$text(msg)
})

app$start()
library(ambiorix)

app <- Ambiorix$new(port = 3000L)

app$get("/:book", function(req, res) {
  res$render(
    "home.html",
    data = list(title = req$params$book)
  )
})

app$start()

<!-- templates/home.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <title>[% title %]</title>
</head>
<body>
  <h1>[% title %]</h1>
  <p>Welcome to Ambiorix!</p>
</body>
</html>
library(ambiorix)

app <- Ambiorix$new(port = 3000L)

# pre-process every request
app$use(function(req, res) {
  cat(sprintf("[%s] %s\n", req$REQUEST_METHOD, req$PATH_INFO))
})

app$get("/", function(req, res) {
  res$send("Hello, World!")
})

app$start()
library(ambiorix)

app <- Ambiorix$new(port = 3000L)

app$get("/", function(req, res) {
  res$send_file("home.html")
})

# listen to incoming websocket messages
app$receive("hello", function(msg, ws) {
  print(msg)
  ws$send("hello", "Hello back! (sent from R)")
})

app$start()
library(future)
library(ambiorix)

plan(multisession)

app <- Ambiorix$new(port = 3000L)

app$get("/async", function(req, res) {
  future({
    Sys.sleep(10)
    res$send(Sys.time())
  })
})

app$get("/sync", function(req, res) {
  res$send(Sys.time())
})

app$start()

Get Started

Build for the web, with R.

Get Started