typescene-async-http v0.1.1
Typescene Async HTTP Library
Simple front-end HTTP request library, part of the Typescene toolkit.
Note: This library can only be used in the browser. To learn more about Typescene, head over to the main Typescene repository.
Purpose of this module
The typescene-async-http library is not, and will never be, a full framework for web application client-server communication.
However, since most applications won't need much more than simple "Ajax"-style REST requests to transfer HTML or JSON data anyway---and there are no simple ways to achieve this in a cross-browser solution using Promises, this library at least provides the basics.
For its implementation of Promises and Signals (for intercepting requests and responses), this module relies on the typescene-async module.
Exported members
The typescene-async-http module exports the following classes and methods:
fetchfunction --- mimics thewindow.fetchfunction in modern browsers. Internally uses either XMLHttpRequest or the native fetch implementation to process requests and responses, and always returns a Promise for a response object.getTextAsyncandgetBlobAsync--- to perform a GET request and return a Promise for the text or blob response data.getHtmlContentAsync--- to perform a GET request and return a Promise for a document fragment that contains everything in the HTML response's<body>.getAsync,postAsync,putAsync, anddeleteAsync--- wrapper functions that send JSON data and return a promise for a parsed JSON response.MockResponseandMockResponseHeaders--- can be used to generate mock responses, and used internally to transform XMLHttpRequest data.RequestingandRespondedsignals --- for intercepting requests and responses.optionsobject --- contains options for default behavior of thefetchfunction.
Refer to the samples for common usage patterns.