|
// requests.wren
|
|
foreign class Response {
|
|
construct new() {}
|
|
|
|
foreign isError
|
|
foreign statusCode
|
|
foreign body
|
|
foreign json()
|
|
}
|
|
|
|
class Requests {
|
|
// Foreign methods now expect a callback function.
|
|
foreign static get_(url, headers, callback)
|
|
foreign static post_(url, body, contentType, headers, callback)
|
|
|
|
static get(url, headers, callback) {
|
|
if (!(callback is Fn) || callback.arity != 2) {
|
|
Fiber.abort("Callback must be a function that accepts 2 arguments: (error, response).")
|
|
}
|
|
get_(url, headers, callback)
|
|
}
|
|
|
|
static post(url, body, headers, callback) {
|
|
if (!(callback is Fn) || callback.arity != 2) {
|
|
Fiber.abort("Callback must be a function that accepts 2 arguments: (error, response).")
|
|
}
|
|
var contentType = headers != null && headers.containsKey("Content-Type") ?
|
|
headers["Content-Type"] : "application/json"
|
|
post_(url, body, contentType, headers, callback)
|
|
}
|
|
}
|