0.1.1 • Published 7 years ago

typescene-async-http v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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:

  • fetch function --- mimics the window.fetch function 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.
  • getTextAsync and getBlobAsync --- 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, and deleteAsync --- wrapper functions that send JSON data and return a promise for a parsed JSON response.
  • MockResponse and MockResponseHeaders --- can be used to generate mock responses, and used internally to transform XMLHttpRequest data.
  • Requesting and Responded signals --- for intercepting requests and responses.
  • options object --- contains options for default behavior of the fetch function.

Refer to the samples for common usage patterns.