Skip to content

Commit

Permalink
feat(example): add simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanebachelier committed Feb 11, 2016
1 parent 54b7a1f commit 9c42154
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
58 changes: 58 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<doctype html>
<html>
<head>
<meta charset="utf8">
<title>Superapi Cache test</title>

<script src="../node_modules/bluebird/js/browser/bluebird.js"></script>
<script src="../node_modules/localforage/dist/localforage.js"></script>
<script src="../node_modules/superapi/dist/superapi.js"></script>
<script src="../node_modules/superagent-dist/superagent.js"></script>
<script src="../dist/superapi-cache.js"></script>
<script>
api = superapi.default({
baseUrl: 'http://localhost:3002',
services: {
person: {
path: '/person/:id'
}
}
});
api.withAgent(superagent);

const superapiCache = window['superapi-cache'];

localforage.setDriver([
localforage.WEBSQL,
localforage.INDEXEDDB,
localforage.LOCALSTORAGE
]);

api.register('cache', superapiCache({
store: localforage,
key: function (req) {
return req.url;
}
}));

api.status(200, function (req, res) {
console.log('200 called for ' + req.url);
});

api.api.person({params: {id: 123456789}})
.then(function (response) {
console.log(response.body);

localforage.getItem('http://localhost:3002/person/123456789').then(function (value) {
console.log(value);
});
})
.catch(function (error) {
debugger;
})

</script>
</head>
<body>
</body>
</html>
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@
"babel-preset-es2015": "^6.3.13",
"babel-tape-runner": "^2.0.0",
"blue-tape": "^0.1.11",
"bluebird": "^3.1.1",
"debug": "^2.2.0",
"eslint": "^1.10.3",
"eslint-loader": "^1.2.0",
"isparta": "^4.0.0",
"localforage": "^1.3.1",
"lodash": "^3.10.1",
"rimraf": "^2.5.0",
"sinon": "^1.17.2",
"standard": "^5.4.1",
"superagent-dist": "^1.6.2",
"superapi": "^0.14.0",
"tap-spec": "^4.1.1",
"tape": "^4.3.0",
"watch": "^0.17.1",
Expand Down

0 comments on commit 9c42154

Please sign in to comment.