1.0.3 • Published 6 years ago
@handout/handout v1.0.3
BETA: Use at your own risk!
Features
- Use of latest web standards to stay small and quick ( check compatibility section for details )
- Track request loading and progress automatically
- Modular and extensible through plugins and events/filters
- Promise-based responses
Installation
install the package:
npm install @handout/handout
import into your code
import Handout from '@handout/handout';
The library is built as an ES6 module, to use it in the browser you need to transpile it using one of the many tools available ( Babel, Bublè, etc )
Quick start
Submit a form on the page
const form = document.querySelector('form');
new Handout(form)
.submit()
.then(response => {
if (response.status >= 400) {
// Handle response error
} else {
// Handle response data
console.log(response.data);
}
}).catch(error => {
// Handle request error
});
Add data programmatically
new Handout('http://your-awesome-api.com', 'post')
.add('name', 'John')
.add('surname', 'Doe')
.submit()
.then(response => {
// Handle response
}).catch(error => {
// Handle errors
});
Events and Filters
The library supports a variety of events and filters to extend its behaviour, for a full list of all events and filters available check the events section.
Plugins
The core functionality is quite basic, but can be easily extended through plugins.
Official plugins:
- Handout/validation Validate field values and display error messages NYI
- Handout/files Beautifully handle file uploads NYI
- More to come!
Compatibility
Chrome | Firefox | Safari | Edge |
---|---|---|---|
last 2 versions | last 2 versions | last 2 versions | Edge |
To support IE11 you need FormData and Promise polyfills