httpuv

HTTP and WebSocket server package for R

https://github.com/rstudio/httpuv

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.7%) to scientific vocabulary

Keywords from Contributors

shiny web-app web-development pandoc geos documentation-tool rmarkdown literate-programming gdal visualisation
Last synced: 10 months ago · JSON representation

Repository

HTTP and WebSocket server package for R

Basic Info
Statistics
  • Stars: 246
  • Watchers: 23
  • Forks: 88
  • Open Issues: 57
  • Releases: 32
Created over 13 years ago · Last pushed 11 months ago
Metadata Files
Readme Changelog Contributing License

README.md

httpuv: HTTP and WebSocket server library for R

<!-- badges: start --> R build status <!-- badges: end -->

httpuv provides low-level socket and protocol support for handling HTTP and WebSocket requests directly from within R. It uses a multithreaded architecture, where I/O is handled on one thread, and the R callbacks are handled on another.

It is primarily intended as a building block for other packages, rather than making it particularly easy to create complete web applications using httpuv alone. httpuv is built on top of the libuv and http-parser C libraries, both of which were developed by Joyent, Inc.

Installing

You can install the stable version from CRAN, or the development version using pak:

```r

install from CRAN

install.packages("httpuv")

or if you want to test the development version here

pak::pak("rstudio/httpuv") ```

Since httpuv contains C code, you'll need to make sure you're set up to install packages with compiled code. Follow the instructions at http://www.rstudio.com/ide/docs/packages/prerequisites

httpuv may optionally be built using a libuv system package, which you can install prior to installing the R package. It goes by different names on different package managers: libuv1-dev (deb), libuv-devel (rpm), libuv (brew). Version 1.43 or greater is required. If libuv is not found on the system, it will be built from source along with the R package.

Basic Usage

This is a basic web server that listens on port 8080 and responds to HTTP requests with a web page containing the current system time and the path of the request:

```R library(httpuv)

s <- startServer(host = "0.0.0.0", port = 8080, app = list( call = function(req) { body <- paste0("Time: ", Sys.time(), "
Path requested: ", req$PATH_INFO) list( status = 200L, headers = list('Content-Type' = 'text/html'), body = body ) } ) ) ```

Note that when host is 0.0.0.0, it listens on all network interfaces. If host is 127.0.0.1, it will only listen to connections from the local host.

The startServer() function takes an app object, which is a named list with functions that are invoked in response to certain events. In the example above, the list contains a function call. This function is invoked when a complete HTTP request is received by the server, and it is passed an environment object req, which contains information about HTTP request. req$PATH_INFO is the path requested (if the request was for http://127.0.0.1:8080/foo, it would be "/foo").

The call function is expected to return a list containing status, headers, and body. That list will be transformed into a HTTP response and sent to the client.

To stop the server:

R s$stop()

Or, to stop all running httpuv servers:

R stopAllServers()

Static paths

A httpuv server application can serve up files on disk. This happens entirely within the I/O thread, so doing so will not block or be blocked by activity in the main R thread.

To serve a path, use staticPaths in the app. This will serve the www/ subdirectory of the current directory (from when startServer is called) as the root of the web path:

R s <- startServer("0.0.0.0", 8080, app = list( staticPaths = list("/" = "www/") ) )

By default, if a file named index.html exists in the directory, it will be served when / is requested.

staticPaths can be combined with call. In this example, the web paths /assets and /lib are served from disk, but requests for any other paths go through the call function.

R s <- startServer("0.0.0.0", 8080, list( call = function(req) { list( status = 200L, headers = list( 'Content-Type' = 'text/html' ), body = "Hello world!" ) }, staticPaths = list( "/assets" = "content/assets/", # Don't use index.html for /lib "/lib" = staticPath("content/lib", indexhtml = FALSE) ) ) )

WebSocket server

httpuv also can handle WebSocket connections. For example, this app acts as a WebSocket echo server:

```R s <- startServer("127.0.0.1", 8080, list( onWSOpen = function(ws) { # The ws object is a WebSocket object cat("Server connection opened.\n")

  ws$onMessage(function(binary, message) {
    cat("Server received message:", message, "\n")
    ws$send(message)
  })
  ws$onClose(function() {
    cat("Server connection closed.\n")
  })
}

) ) ```

To test it out, you can connect to it using the websocket package (which provides a WebSocket client). You can do this from the same R process or a different one.

```R ws <- websocket::WebSocket$new("ws://127.0.0.1:8080/") ws$onMessage(function(event) { cat("Client received message:", event$data, "\n") })

Wait for a moment before running next line

ws$send("hello world")

Close client

ws$close() ```

Note that both the httpuv and websocket packages provide a class named WebSocket; however, in httpuv, that class acts as a server, and in websocket, it acts as a client. They also have different APIs. For more information about the WebSocket client package, see the project page.


Debugging builds

httpuv can be built with debugging options enabled. This can be done by uncommenting these lines in src/Makevars, and then installing. The first one enables thread assertions, to ensure that code is running on the correct thread; if not. The second one enables tracing statements: httpuv will print lots of messages when various events occur.

PKG_CPPFLAGS += -DDEBUG_THREAD -UNDEBUG PKG_CPPFLAGS += -DDEBUG_TRACE

To install it directly from GitHub with these options, you can use with_makevars, like this:

R withr::with_makevars( c(PKG_CPPFLAGS="-DDEBUG_TRACE -DDEBUG_THREAD -UNDEBUG"), { devtools::install_github("rstudio/httpuv") }, assignment = "+=" )

© 2013-2020 RStudio, Inc.

Owner

  • Name: RStudio
  • Login: rstudio
  • Kind: organization
  • Email: info@rstudio.org
  • Location: Boston, MA

GitHub Events

Total
  • Create event: 11
  • Issues event: 15
  • Watch event: 14
  • Delete event: 7
  • Member event: 1
  • Issue comment event: 17
  • Push event: 34
  • Pull request review comment event: 5
  • Pull request review event: 3
  • Pull request event: 16
  • Fork event: 2
Last Year
  • Create event: 11
  • Issues event: 15
  • Watch event: 14
  • Delete event: 7
  • Member event: 1
  • Issue comment event: 17
  • Push event: 34
  • Pull request review comment event: 5
  • Pull request review event: 3
  • Pull request event: 16
  • Fork event: 2

Committers

Last synced: 12 months ago

All Time
  • Total Commits: 810
  • Total Committers: 27
  • Avg Commits per committer: 30.0
  • Development Distribution Score (DDS): 0.415
Past Year
  • Commits: 10
  • Committers: 3
  • Avg Commits per committer: 3.333
  • Development Distribution Score (DDS): 0.6
Top Committers
Name Email Commits
Winston Chang w****n@s****g 474
Joe Cheng j****e@r****m 210
Barret Schloerke s****e@g****m 36
Garrick Aden-Buie g****k@a****m 22
Neal Richardson n****n@g****m 10
Carson Sievert c****1@g****m 9
Jeroen j****s@g****m 8
hcorrada h****a@g****m 7
Alan Dipert a****n@d****g 6
Charlie Gao 5****o 4
Yihui Xie x****e@y****e 3
Aaron Jacobs a****l@g****m 2
gifi n****c@o****m 2
Matt Sandy m****s@g****m 2
Lars-Dominik Braun l****s@6****t 2
Lars Haferkamp l****p@c****m 2
Dominik Ernst de@d****g 1
shalu tiwari s****i@s****l 1
ismirsehregal 3****l 1
hadley wickham h****m@g****m 1
Zain Rizvi z****r@g****m 1
Sebastian s****c 1
Salim B g****t@s****e 1
Nick Strayer n****r@r****m 1
Gary g****y@r****m 1
Elliott Sales de Andrade q****t@g****m 1
Colin Rundel r****l@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 74
  • Total pull requests: 92
  • Average time to close issues: 4 months
  • Average time to close pull requests: 26 days
  • Total issue authors: 52
  • Total pull request authors: 22
  • Average comments per issue: 2.84
  • Average comments per pull request: 1.24
  • Merged pull requests: 72
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 12
  • Pull requests: 20
  • Average time to close issues: 1 day
  • Average time to close pull requests: 5 days
  • Issue authors: 10
  • Pull request authors: 4
  • Average comments per issue: 0.17
  • Average comments per pull request: 0.25
  • Merged pull requests: 14
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jcheng5 (6)
  • schloerke (4)
  • shikokuchuo (3)
  • atheriel (3)
  • wch (3)
  • tconwell (2)
  • msoehren (2)
  • gadenbuie (2)
  • cpsievert (2)
  • nealrichardson (2)
  • meztez (2)
  • jeroen (2)
  • colearendt (1)
  • skratkk (1)
  • mojaveazure (1)
Pull Request Authors
  • wch (25)
  • jcheng5 (12)
  • schloerke (10)
  • gadenbuie (10)
  • cpsievert (9)
  • shikokuchuo (8)
  • atheriel (3)
  • nealrichardson (3)
  • salim-b (2)
  • gtritchie (1)
  • ismirsehregal (1)
  • kevinushey (1)
  • vikram-rawat (1)
  • actsasflinn (1)
  • barracuda156 (1)
Top Labels
Issue Labels
upkeep (1)
Pull Request Labels
upkeep (1) documentation (1)

Packages

  • Total packages: 3
  • Total downloads:
    • cran 471,108 last-month
  • Total docker downloads: 59,581,922
  • Total dependent packages: 86
    (may contain duplicates)
  • Total dependent repositories: 928
    (may contain duplicates)
  • Total versions: 101
  • Total maintainers: 1
cran.r-project.org: httpuv

HTTP and WebSocket Server Library

  • Versions: 45
  • Dependent Packages: 72
  • Dependent Repositories: 892
  • Downloads: 471,108 Last month
  • Docker Downloads: 59,581,922
Rankings
Dependent repos count: 0.4%
Downloads: 0.5%
Forks count: 0.8%
Dependent packages count: 1.2%
Stargazers count: 1.9%
Average: 3.7%
Docker downloads count: 17.3%
Maintainers (1)
Last synced: 11 months ago
proxy.golang.org: github.com/rstudio/httpuv
  • Versions: 39
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 9.0%
Average: 9.6%
Dependent repos count: 10.2%
Last synced: 11 months ago
conda-forge.org: r-httpuv
  • Versions: 17
  • Dependent Packages: 14
  • Dependent Repositories: 36
Rankings
Dependent packages count: 4.5%
Dependent repos count: 6.1%
Average: 14.1%
Forks count: 20.2%
Stargazers count: 25.5%
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • R >= 2.15.1 depends
  • R6 * imports
  • Rcpp >= 1.0.7 imports
  • later >= 0.8.0 imports
  • promises * imports
  • utils * imports
  • callr * suggests
  • curl * suggests
  • testthat * suggests
  • websocket * suggests
src/libuv/docs/requirements.txt pypi
  • Babel ==2.9.0
  • CacheControl ==0.12.6
  • Jinja2 ==2.11.3
  • MarkupSafe ==1.1.1
  • Pygments ==2.8.1
  • Sphinx ==3.5.4
  • alabaster ==0.7.12
  • appdirs ==1.4.3
  • certifi ==2019.11.28
  • chardet ==3.0.4
  • colorama ==0.4.3
  • contextlib2 ==0.6.0
  • distlib ==0.3.0
  • distro ==1.4.0
  • docutils ==0.16
  • html5lib ==1.0.1
  • idna ==2.8
  • imagesize ==1.2.0
  • ipaddr ==2.2.0
  • lockfile ==0.12.2
  • msgpack ==0.6.2
  • packaging ==20.3
  • pep517 ==0.8.2
  • progress ==1.5
  • pyparsing ==2.4.6
  • pytoml ==0.1.21
  • pytz ==2021.1
  • requests ==2.22.0
  • retrying ==1.3.3
  • six ==1.14.0
  • snowballstemmer ==2.1.0
  • sphinxcontrib-applehelp ==1.0.2
  • sphinxcontrib-devhelp ==1.0.2
  • sphinxcontrib-htmlhelp ==1.0.3
  • sphinxcontrib-jsmath ==1.0.1
  • sphinxcontrib-qthelp ==1.0.3
  • sphinxcontrib-serializinghtml ==1.1.4
  • urllib3 ==1.25.8
  • webencodings ==0.5.1