koa-hap-client
koa-hap-client is the ajax library for Hap protocol.
it's use with server-side koa-hap as suite.
to build hap application as quickly.
quick start
install
npm install koa-hap-client
use in browser
export async index({ name }) {
return `Hello ${name}!`
}
<script src="node_modules/koa-hap-client/dist/hap.js"></script>
<script>
var api = hap('/api', {
})
api.hello({ name: 'World' }).then(function (result) {
document.write(result);
}).catch(function (err) {
document.write(err);
});
hap.api.hello({ name: 'World' }).then((result)=> {
document.write(result);
}).catch(function (err) {
document.write(err);
});
</script>
use in node or webpack
import hap from 'koa-hap-client';
const api = hap('/api', {});
async () => {
let result = await api.hello({ name: 'World' });
result = hap.api.hello({ name: 'World' });
}
examples
pls see koa-hap-example
doc
with axios config
hap(baseUrl, config)
return hap with config.
. operator
then . operator is auto transform member path to url like this:
hap.a.b.c.d.e({})
const api = hap('/api', {})
api.example.hello({ name: "World" })