MyNixOS website logo
Description

A Framework for Building HTTP API.

Allows to easily create high-performance full featured HTTP APIs from R functions. Provides high-level classes such as 'Request', 'Response', 'Application', 'Middleware' in order to streamline server side application development. Out of the box allows to serve requests using 'Rserve' package, but flexible enough to integrate with other HTTP servers such as 'httpuv'.

RestRserve

R build status CRAN status codecov License Lifecycle: stable gitter tinyverse

RestRserve is an R web API framework for building high-performance AND robust microservices and app backends. On UNIX-like systems and Rserve backend RestRserve handles requests in parallel: each request in a separate fork - credits go to Simon Urbanek.

Quick start

Creating application is as simple as:

library(RestRserve)
app = Application$new()

app$add_get(
  path = "/health", 
  FUN = function(.req, .res) {
    .res$set_body("OK")
  })

app$add_post(
  path = "/addone", 
  FUN = function(.req, .res) {
    result = list(x = .req$body$x + 1L)
    .res$set_content_type("application/json")
    .res$set_body(result)
  })


backend = BackendRserve$new()
backend$start(app, http_port = 8080)

Test it with curl:

curl localhost:8080/health
# OK
curl -H "Content-Type: application/json" -d '{"x":10}' localhost:8080/addone
# {"x":11}

Autocomplete

Using convenient .req, .res names for handler arguments allows to leverage autocomplete.

Learn RestRserve

Features

  • Stable, easy to install, few dependencies
  • Concise and intuitive syntax
  • Well documented, comes with many examples - see inst/examples
  • Fully featured http server with the support for URL encoded and multipart forms
  • Build safe and secure applications - RestRserve supports https, provides building blocks for basic/token authentication
  • Raise meaningful http errors and allows to interrupt request handling from any place of the user code
  • Saves you from boilerplate code:
    • automatically decodes request body from the common formats
    • automatically encodes response body to the common formats
    • automatically parses URI templates (such as /get/{item_id})
    • helps to expose OpenAPI and Swagger/Redoc/Rapidoc UI
  • It is fast!

Installation

From CRAN

install.packages("RestRserve", repos = "https://cloud.r-project.org")

Docker

Debian and Alpine based images are available on docker-hub -https://hub.docker.com/r/rexyai/restrserve/

docker pull rexyai/restrserve

You can also install specific version (and we encourage to do so):

docker pull rexyai/restrserve:1.2.0-alpine

Contributing

Guidelines for filing issues / pull requests - CONTRIBUTING.md.

Acknowledgements

  • Simon Urbanek (@s-u) for awesome Rserve and all the work on R itself and on his other packages
  • Jeff Allen (@trestletech) for his work on Swagger UI in plumber (from where we took inspiration for our implementation)
  • Brodie Gaslam (@brodieG) for help with understanding on how to get traceback from try-catch function calls. Also thanks Hadley Wickham (@hadley) for evaluate::try_capture_stack function which we use for this purpose.

Known limitations

  • RestRserve is primarily tested on UNIX systems. While it works natively on Windows please don't expect it to be as performant as on UNIX-like systems. If you really want to use it on Windows - consider to use Windows Subsystem for Linux.
  • Keep in mind that every request is handled in a separate process (fork from a parent R session). While this feature allows to handle requests in parallel it also restricts reuse of certain objects which are not fork-safe (notably database connections, rJava objects, etc)

Related projects

Metadata

Version

1.2.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows