- Notifications
You must be signed in to change notification settings - Fork13
A flexible and lightweight web server
License
Unknown, MIT licenses found
Licenses found
thomasp85/fiery
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Fiery is a flexible and lightweight framework for building web serversin R. It is relatively unopinionated about how you chose to build yourserver logic and supports many use cases, from serving static files tobeing used as a base for a model-view-controller based setup.
Install the release from CRAN usinginstall.packages('fiery') or getthe development version directly from GitHub usingpak:
# install.packages('pak')pak::pak('thomasp85/fiery')
Fiery is designed around a clear server life-cycle with events beingtriggered at specific points during the life-cycle that will call thehandlers attached to these events. In addition to the life-cycle events,it is possible to trigger custom events and attach handlers to these aswell. Fiery is designed with modularity in mind so that plugins can bedeveloped for different tasks and mixed and matched to suit the specificproject.
While the intro might indicate that fiery is difficult to use, this isnot the case. Much of the hard work of handling http requests has beenencapsulated in thereqres thatfiery uses to handle http requests and responses. Further, A plugin thatwill often be used isroutr,which provides powerful routing of HTTP requests, thus simplifying theserver logic even more.
Following is a veryHello World-ish example of a fiery app (sansroutr), that showcases some of the different life-cycle events:
library(fiery)# Create a New Appapp<-Fire$new()# Setup the data every time it startsapp$on('start',function(server,...) {server$set_data('visits',0)server$set_data('cycles',0)})# Count the number of cycles (internal loops)app$on('cycle-start',function(server,...) {server$set_data('cycles',server$get_data('cycles')+1)})# Count the number of requestsapp$on('before-request',function(server,...) {server$set_data('visits',server$get_data('visits')+1)})# Handle requestsapp$on('request',function(server,request,...) {response<-request$respond()response$status<-200Lresponse$body<- paste0('<h1>This is indeed a test. You are number',server$get_data('visits'),'</h1>')response$type<-'html'})# Show number of requests in the consoleapp$on('after-request',function(server,...) { message(server$get_data('visits')) flush.console()})# Terminate the server after 50 cyclesapp$on('cycle-end',function(server,...) {if (server$get_data('cycles')>50) { message('Ending...') flush.console()server$extinguish() }})# Be politeapp$on('end',function(server) { message('Goodbye') flush.console()})app$ignite(showcase=TRUE)#> Fire started at <127.0.0.1:8080> (narrow_factional_pygmy)#> Goodbye
In general much of the logic will happen in therequest andmessagehandlers and you are free to ignore the other life-cycle events if theyare not needed.
Please note that the ‘fiery’ project is released with aContributorCode of Conduct.By contributing to this project, you agree to abide by its terms.
About
A flexible and lightweight web server
Topics
Resources
License
Unknown, MIT licenses found
Licenses found
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
