A Scriptable package that handles two-way communication between a WebView and the Scriptable app.
const Saab = require("Saab");
const saab = Saab();
// saab.use(path, handler)
// saab.get(path, handler)
// saab.post(path, handler)
// saab.put(path, handler)
// saab.delete(path, handler)
// saab.listen(wv)
The use
method will handle any request method. Each other method handles their respective request method.
- path A string indicating the path to match. See
path-to-regexp-scriptable
for acceptable values - handler A handler method of the form
(req, res) => {}
- req The request object
- method The request method (get|post|put|delete)
- path The request path (eg. /customer)
- payload The request payload object
- params The request route params
- res The response object
- error Sends an error response
- val The error object or string to send
- send Sends a response
- str The string response to send
- json Sends a json response
- obj The json object to send
- error Sends an error response
- req The request object
The listen
function starts the listener on the given wv
- wv The WebView instance to start listening for requests on
The package will add an saab
object on the window
in the WebView
// window.saab.request(config)
// window.saab.get(path, payload?, config?)
// window.saab.post(path, payload?, config?)
// window.saab.put(path, payload?, config?)
// window.saab.delete(path, payload?, config?)
The request
method will send a request with the given config
.
- config The request config
- method The request method (get|post|put|delete)
- path The request path
- payload The request payload object
- ...props Any additional config properties
These methods will send a request with the given config
and their respective request method.
- path The request path
- payload The request payload object
- config An object holding any additional config properties