Package ‘plumber’

2y ago
50 Views
2 Downloads
203.57 KB
55 Pages
Last View : 8d ago
Last Download : 3m ago
Upload by : Lilly Andre
Transcription

Package ‘plumber’March 23, 2021Encoding UTF-8Type PackageTitle An API Generator for RVersion 1.1.0Roxygen list(markdown TRUE)License MIT file LICENSEBugReports https://github.com/rstudio/plumber/issuesURL https://www.rplumber.io, https://github.com/rstudio/plumberDescription Gives the ability to automatically generate and serve an HTTP APIfrom R functions using the annotations in the R documentation around yourfunctions.Depends R ( 3.0.0)Imports R6 ( 2.0.0),stringi ( 0.3.0),jsonlite ( 0.9.16),webutils ( 1.1),httpuv ( 1.5.0),crayon,promises ( 1.1.0),sodium,swagger ( 3.33.0),magrittr,mime,lifecycle ( 0.2.0),ellipsis ( 0.3.0),rlangLazyData TRUEByteCompile TRUESuggests testthat ( ,later,readr,1

R topics g,mockery ( 0.4.2)RoxygenNote 7.1.1Collate t.R''openapi-spec.R''openapi-types.R''options lumber-step.R''pr.R''pr R''utils-pipe.R''utils.R''validate api spec.R''zzz.R'RdMacros lifecycleLanguage en-USR topics documented:as attachment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .endpoint serializer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34

as attachment3forward . . . . . . .get character set . .include file . . . . .is plumber . . . . .options plumber . .parser form . . . . .plumb . . . . . . . .Plumber . . . . . . .PlumberEndpoint . .PlumberStatic . . . .PlumberStep . . . . .plumb api . . . . . .pr . . . . . . . . . .pr cookie . . . . . .pr filter . . . . . . .pr handle . . . . . .pr hook . . . . . . .pr mount . . . . . .pr run . . . . . . . .pr set 404 . . . . . .pr set api spec . . .pr set debug . . . .pr set docs . . . . .pr set docs callbackpr set error . . . . .pr set parsers . . . .pr set serializer . . .pr static . . . . . . .random cookie key .register docs . . . .register parser . . . .register serializer . .serializer headers . .session cookie . . .validate api spec . .Indexas 041424243444445464748515354Return an attachment responseDescriptionThis will set the appropriate fields in the Content-Disposition header value. To make sure theattachment is used, be sure your serializer eventually calls serializer headersUsageas attachment(value, filename NULL)

4endpoint serializerArgumentsvalueResponse value to be savedfilenameFile name to use when saving the attachment. If no filename is provided, thevalue will be treated as a regular attachmentValueObject with class "plumber attachment"Examples## Not run:# plumber.R#' @get /data#' @serializer csvfunction() {# will cause the file to be saved as iris.csv , not data or data.csv as attachment(iris, "iris.csv")}## End(Not run)endpoint serializerEndpoint Serializer with HooksDescriptionThis method allows serializers to return preexec, postexec, and aroundexec ([Experimental])hooks in addition to a serializer. This is useful for graphics device serializers which need a preexecand postexec hook to capture the graphics output.Usageendpoint serializer(serializer,preexec hook NULL,postexec hook NULL,aroundexec hook NULL)ArgumentsserializerSerializer method to be used. This method should already have its initializationarguments applied.preexec hookFunction to be run directly before a PlumberEndpoint calls its route method.postexec hook Function to be run directly after a PlumberEndpoint calls its route method.aroundexec hookFunction to be run around a PlumberEndpoint call. Must handle a .next argument to continue execution. [Experimental]

forward5Detailspreexec and postexec hooks happened directly before and after a route is executed. These hooksare specific to a single PlumberEndpoint’s route calculation.Examples# The definition of serializer device returns# * a serializer content type serializer# * aroundexec hookprint(serializer device)forwardForward Request to The Next HandlerDescriptionThis function is used when a filter is done processing a request and wishes to pass control off tothe next handler in the chain. If this is not called by a filter, the assumption is that the filter fullyhandled the request itself and no other filters or endpoints should be evaluated for this request.Usageforward()get character setRequest character setDescriptionRequest character setUsageget character set(content type NULL)Argumentscontent typeRequest Content-Type headerValueDefault to UTF-8. Otherwise return charset defined in request header.

6is plumberinclude fileSend File Contents as ResponseDescriptionReturns the file at the given path as the response. If you want an endpoint to return a file as anattachment for user to download see as attachment().Usageinclude file(file, res, content type getContentType(tools::file ext(file)))include html(file, res)include md(file, res, format NULL)include rmd(file, res, format NULL)ArgumentsfileThe path to the file to returnresThe response object into which we’ll writecontent typeIf provided, the given value will be sent as the Content-Type header in theresponse. Defaults to the contentType of the file extension. To disable theContent-Type header, set content type NULL.formatPassed as the output format to rmarkdown::renderDetailsinclude html will merely return the file with the proper content type for HTML. include mdand include rmd will process the given markdown file through rmarkdown::render and returnthe resultant HTML as a response.is plumberDetermine if Plumber objectDescriptionDetermine if Plumber objectUsageis plumber(pr)ArgumentsprHopefully a Plumber object

options plumber7ValueLogical value if pr inherits from PlumberExamplesis plumber(Plumber new()) # TRUEis plumber(list()) # FALSEoptions plumberPlumber optionsDescriptionThere are a number of global options that affect Plumber’s behavior. These can be set globallywith options() or with options plumber(). Options set using options plumber() should notinclude the plumber. prefix.Usageoptions plumber(.,port getOption("plumber.port"),docs getOption("plumber.docs"),docs.callback getOption("plumber.docs.callback"),trailingSlash d getOption("plumber.methodNotAllowed"),apiURL getOption("plumber.apiURL"),apiScheme getOption("plumber.apiScheme"),apiHost getOption("plumber.apiHost"),apiPort getOption("plumber.apiPort"),apiPath getOption("plumber.apiPath"),maxRequestSize getOption("plumber.maxRequestSize"),sharedSecret getOption("plumber.sharedSecret"),legacyRedirects ored. Should be emptyport, docs, docs.callback, trailingSlash, methodNotAllowed, apiScheme, apiHost, apiPort, apiPath, apiSee detailsDetailsplumber.port Port Plumber will attempt to use to start http server. If the port is already in use,server will not be able to start. Defaults to NULL.plumber.docs Name of the visual documentation interface to use. Defaults to TRUE, which willuse "swagger".plumber.docs.callback A function. Called with a single parameter corresponding to the visualdocumentation url after Plumber server is ready. This can be used by RStudio to open the docswhen then API is ran from the editor. Defaults to option NULL.

8parser formplumber.trailingSlash Logical value which allows the router to redirect any request that hasa matching route with a trailing slash. For example, if set to TRUE and the GET route /test/existed, then a GET request of /test?a 1 would redirect to /test/?a 1. Defaults to FALSE. Thisoption will default to TRUE in a future release.plumber.methodNotAllowed [Experimental] Logical value which allows the router to notify thatan unavailable method was requested, but a different request method is allowed. For example,if set to TRUE and the GET route /test existed, then a POST request of /test would receive a405 status and the allowed methods. Defaults to TRUE.plumber.apiURL Server urls for OpenAPI Specification respecting pattern scheme://host:port/path.Other api* options will be ignored when set.plumber.apiScheme Scheme used to build OpenAPI url and server url for OpenAPI Specification.Defaults to http, or an empty string when used outside a running router.plumber.apiHost Host used to build docs url and server url for OpenAPI Specification. Defaultsto host defined by run method, or an empty string when used outside a running router.plumber.apiPort Port used to build OpenAPI url and server url for OpenAPI Specification. Defaults to port defined by run method, or an empty string when used outside a running router.plumber.apiPath Path used to build OpenAPI url and server url for OpenAPI Specification. Defaults to an empty string.plumber.maxRequestSize Maximum length in bytes of request body. Body larger than maximumare rejected with http error 413. 0 means unlimited size. Defaults to 0.plumber.sharedSecret Shared secret used to filter incoming request. When NULL, secret is notvalidated. Otherwise, Plumber compares secret with http header PLUMBER SHARED SECRET.Failure to match results in http error 400. Defaults to NULL.plumber.legacyRedirects Plumber will redirect legacy route / swagger / and / swagger /index.htmlto ./ docs / and ./ docs /index.html. You can disable this by settings this option toFALSE. Defaults to TRUEValueThe complete, prior set of options() values. If a particular parameter is not supplied, it will returnthe current value. If no parameters are supplied, all returned values will be the current options()values.parser formPlumber ParsersDescriptionParsers are used in Plumber to transform request body received by the API. Extra parameters maybe provided to parser functions when enabling them on router. This will allow for non-defaultbehavior.Usageparser form()parser json(.)

parser form9parser text(parse fn identity)parser yaml(.)parser csv(.)parser tsv(.)parser read file(read fn readLines)parser rds(.)parser feather(.)parser octet()parser multi()parser none()Arguments.parameters supplied to the appropriate internal functionparse fnfunction to further decode a text string into an objectread fnfunction used to read a the content of a file. Ex: readRDS()DetailsParsers are optional. When unspecified, only default endpoint parsers are enabled. You can use@parser NAME tag to enable parser on endpoint. Multiple parsers can be enabled on the sameendpoint using multiple @parser NAME tags.User should be aware that rds parsing should only be done from a trusted source. Do not acceptrds files blindly.See registered parsers() for a list of registered parsers names.Functions parser form: Form query string parser parser json: JSON parser. See jsonlite::parse json() for more details. (Defaults tousing simplifyVectors TRUE) parser text: Helper parser to parse plain text parser yaml: YAML parser. See yaml::yaml.load() for more details. parser csv: CSV parser. See readr::read csv() for more details. parser tsv: TSV parser. See readr::read tsv() for more details. parser read file: Helper parser that writes the binary body to a file and reads it back againusing read fn. This parser should be used when reading from a file is required. parser rds: RDS parser. See readRDS() for more details. parser feather: feather parser. See feather::read feather() for more details. parser octet: Octet stream parser. Returns the raw content.

10plumb parser multi: Multi part parser. This parser will then parse each individual body with itsrespective parser. When this parser is used, req body will contain the updated output fromwebutils::parse multipart() by adding the parsed output to each part. Each part maycontain detailed information, such as name (required), content type, content disposition,filename, (raw, original) value, and parsed (parsed value). When performing Plumberroute argument matching, each multipart part will match its name to the parsed content. parser none: No parser. Will not process the postBody.Examples## Not run:# Overwrite text/json parsing behavior to not allow JSON vectors to be simplified#* @parser json simplifyVector FALSE# Activate rds parser in a multipart request#* @parser multi#* @parser rdspr - Plumber new()pr handle("GET", "/upload", function(rds) {rds}, parsers c("multi", "rds"))## End(Not run)plumbProcess a Plumber APIDescriptionProcess a Plumber APIUsageplumb(file NULL, dir ".")ArgumentsfileThe file to parse as the plumber router definition.dirThe directory containing the plumber.R file to parse as the plumber router definition. Alternatively, if an entrypoint.R file is found, it will take precedenceand be responsible for returning a runnable router.DetailsAPI routers are the core request handler in plumber. A router is responsible for taking an incomingrequest, submitting it through the appropriate filters and eventually to a corresponding endpoint, ifone is found.See the Programmatic Usage article for additional details on the methods available on this object.

Plumber11PlumberPackage Plumber RouterDescriptionPackage Plumber RouterPackage Plumber RouterDetailsRouters are the core request handler in plumber. A router is responsible for taking an incomingrequest, submitting it through the appropriate filters and eventually to a corresponding endpoint, ifone is found.See the Programmatic Usage article for additional details on the methods available on this object.Super classplumber::Hookable - PlumberPublic fieldsflags For internal use onlyActive bindingsendpoints Plumber router endpoints read-onlyfilters Plumber router filters read-onlymounts Plumber router mounts read-onlyenvironment Plumber router environment read-onlyroutes Plumber router routes read-onlyMethodsPublic methods: Plumber new()Plumber run()Plumber mount()Plumber unmount()Plumber registerHook()Plumber handle()Plumber removeHandle()Plumber print()Plumber serve()Plumber route()Plumber call()Plumber onHeaders()Plumber onWSOpen()

12Plumber Plumber setSerializer()Plumber setParsers()Plumber set404Handler()Plumber setErrorHandler()Plumber setDocs()Plumber setDocsCallback()Plumber setDebug()Plumber getDebug()Plumber filter()Plumber setApiSpec()Plumber getApiSpec()Plumber addEndpoint()Plumber addAssets()Plumber addFilter()Plumber addGlobalProcessor()Plumber openAPIFile()Plumber swaggerFile()Plumber clone()Method new(): Create a new Plumber routerSee also plumb(), pr()Usage:Plumber new(file NULL, filters defaultPlumberFilters, envir)Arguments:file path to file to plumbfilters a list of Plumber filtersenvir an environment to be used as the enclosure for the routers executionReturns: A new Plumber routerMethod run(): Start a server using Plumber object.See also: pr run()Usage:Plumber run(host "127.0.0.1",port getOption("plumber.port", NULL),swagger deprecated(),debug missing arg(),swaggerCallback missing arg(),.,docs missing arg(),quiet FALSE)Arguments:host a string that is a valid IPv4 or IPv6 address that is owned by this server, which the application will listen on. "0.0.0.0" represents all IPv4 addresses and "::/0" represents all IPv6addresses.

Plumber13port a number or integer that indicates the server port that should be listened on. Note that onmost Unix-like systems including Linux and Mac OS X, port numbers smaller than 1025require root privileges.This value does not need to be explicitly assigned. To explicitly set it, see options plumber().swagger Deprecated. Please use docs instead. See setDocs(docs) or setApiSpec() for morecustomization.debug If TRUE, it will provide more insight into your API errors. Using this value will onlylast for the duration of the run. If a setDebug() has not been called, debug will default tointeractive() at run() time. See setDebug() for more details.swaggerCallback An optional single-argument function that is called back with the URL toan OpenAPI user interface when one becomes ready. If missing, defaults to informationpreviously set with setDocsCallback(). This value will only be used while running therouter. Should be empty.docs Visual documentation value to use while running the API. This value will only be usedwhile running the router. If missing, defaults to information previously set with setDocs().For more customization, see setDocs() or pr set docs() for examples.quiet If TRUE, don’t print routine startup messages.Method mount(): Mount a Plumber routerPlumber routers can be “nested” by mounting one into another using the mount() method. Thisallows you to compartmentalize your API by paths which is a great technique for decomposinglarge APIs into smaller files.See also: pr mount()Usage:Plumber mount(path, router)Arguments:path a character string. Where to mount router.router a Plumber router. Router to be mounted.Examples:\dontrun{root - pr()users - Plumber new("users.R")root mount("/users", users)products - Plumber new("products.R")root mount("/products", products)}Method unmount(): Unmount a Plumber routerUsage:Plumber unmount(path)Arguments:path a character string. Where to unmount router.Method registerHook(): Register a hookPlumber routers support the notion of "hooks" that can be registered to execute some code at aparticular point in the lifecycle of a request. Plumber routers currently support four hooks:

postserialize(data,req,res,value)In all of the above you have access to a disposable environment in the data parameter that iscreated as a temporary data store for each request. Hooks can store temporary data in these hooksthat can be reused by other hooks processing this same request.One feature when defining hooks in Plumber routers is the ability to modify the returned value.The convention for such hooks is: any function that accepts a parameter named value is expectedto return the new value. This could be an unmodified version of the value that was passed in, orit could be a mutated value. But in either case, if your hook accepts a parameter named value,whatever your hook returns will be used as the new value for the response.You can add hooks using the registerHook method, or you can add multiple hooks at once usingthe registerHooks method which takes a name list in which the names are

plumber.docs Name of the visual documentation interface to use. Defaults to TRUE, which will use "swagger". plumber.docs.callback A function. Called with a single parameter corresponding to the visual documentation url after Plumber server is ready. This can be used by RStudio to open the docs

Related Documents:

Master Plumber Examination The qualification requirements are: 1. Two years and 3,750 hours of work experience as a Journeyman under a licensed Master Plumber or Master Plumber/Gasfitter. Copies of W-2's, employment payroll records, 1099's, etc. documenting 2 years work experience under a

1 Exam Prep –Plumber’s Handbook 1 1 Exam Prep Plumber’s Handbook Tabs and Highlights These 1 Exam Prep Tabs are based on the Plumber’s Handbook Revised 2006. Each Tabs sheet has five rows of tabs. Start with the first tab at the first row at the top of the page; proceed down tha

of the requirements for obtaining a plumber license . Three classes of licenses are offered: Journeyman Plumber, Master Plumber Class I (Restricted), and Master Plumber Class II (Unrestricted) . Please review this bulletin carefully . It provides you with information you need abo

MASTER PLUMBER EXAM APPLICATION Please indicate the license that is being used to apply for the exam: Journeyman Plumber License Restricted Master Plumber License Engineering License If you are applying as an engineer, please provide a copy of your current license issued by the Professional

Oct 18, 2021 · Apodaca, David H. Plumber De Leon, Jose L. Proposed Plumber Dubois, Robert E. Proposed Plumber Vacant (Vargas) Facilities Tech Avalos, David Plumber Lead Munoz, Michael C. . Florentino Rivera Groundskeeper Supervisor David Cooper Orlando Flores Groundskeeper Supervisor David Silva Lead Groundskeeper

Sandy, Utah 84070 Phone: (877) 228-3926 www.provexam.com Hours: 6 a.m. to 10 p.m. GENERAL TESTING INFORMATION The Division has contracted with Prov, Inc. to administer the following Plumbing exams: Utah Journeyman Plumber Utah Residential Journeyman Plumber Utah Master Plumber Utah Residential Master Plumber

Package style descriptive code LQFP (low profile quad flat package) Package body material type P (plastic) JEDEC package outline code MS-026 BCD Mounting method type S (surface mount) Issue date 25-01-2016 Manufacturer package code 98ASS23234W Table 1. Package summary Parameter Min Nom Max Unit package length 9.8 10 10.2 mm package width 9.8 10 .

Barbara Jenkins Blessed Mother Candle burns in memory of: Intentions of Kate Prendergast The St. Joseph Candle burns in memory of: Andrew J. Valosky, Jr. People become famous for many different reasons. Some are famous because they have power and influence and others because they do something that is unique or newsworthy. In this Sunday’s Gospel, we hear that Jesus’ fame spread throughout .