https://github.com/kapouer/window-agent
Yet another browser agent, supports callback or promise, and parameters replacement
https://github.com/kapouer/window-agent
promise querystrings xhr
Last synced: 10 months ago
JSON representation
Yet another browser agent, supports callback or promise, and parameters replacement
- Host: GitHub
- URL: https://github.com/kapouer/window-agent
- Owner: kapouer
- License: mit
- Created: 2016-06-15T20:06:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-16T10:27:36.000Z (over 8 years ago)
- Last Synced: 2025-01-29T11:51:50.534Z (12 months ago)
- Topics: promise, querystrings, xhr
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
window-agent
============
Why another xhr agent ?
-----------------------
* no deps, no module loading
* callback or promise
* parameters replacement in url
* takes advantage of browsers ability to parse requested html as DOM document
Install
-------
```
npm install window-agent
cd public;
ln -s ../node_modules/window-agent/agent.js
```
Usage
-----
window.METHOD where METHOD is HEAD, GET, COPY, PUT, PATCH, DELETE, POST.
```
// GET /api/mycollection/45?eager=true&type=a&type=b
window.GET("/api/mycollection/:id", {
id: 45,
eager: true,
type: ["a", "b"]
}).then(function(item) {
// supports promise style
});
window.POST("/api/mycollection/:id", {
id: 45 // can replace variables in url
}, { // body, can also be already json since vers 1.1
somekey: data
}, function(err, result) {
// supports callback style as well
});
// /templates/test.html?lang=fr
window.GET({
url: "/templates/test.html",
type: "html" // tells it to return the document, not the string
}, {
lang:"fr"
}).then(function(doc) {
// doc.documentElement
});
```
License
-------
See LICENSE file.
Future
------
Will probably wrap Fetch API at some point.