🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

koa-hap-client

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-hap-client

the koa-hap client js for borwser and node.js sideserver-[2~side.

latest
Source
npmnpm
Version
0.1.16
Version published
Weekly downloads
2
-91.3%
Maintainers
1
Weekly downloads
 
Created
Source

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

// file: /api/hello.js

// Hap Service "hello" binding to url "/api/hello".
export async index({ name }) {
  return `Hello ${name}!`
}

<!-- call the hap service, url: "/api/hello", params: { name: "World" }. -->
  <script src="node_modules/koa-hap-client/dist/hap.js"></script>
  <script>
    // create api caller.
    var api = hap('/api', {
      //...with axios options
    })

    api.hello({ name: 'World' }).then(function (result) {
      document.write(result); // Hello World!
    }).catch(function (err) {
      document.write(err);
    });

    //// and you can use default axios options aslo.
    ////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' });

  //// or with then default axios options
  //// result = hap.api.hello({ name: 'World' });
}

examples

pls see koa-hap-example

doc

with axios config

hap(baseUrl, config)

paramtypedescript
baseUrlstringthe hap service url
configobjectaxios request config

return hap with config.

. operator

then . operator is auto transform member path to url like this:


////hap.a.b.c.d.e({})
//// POST /a/b/c/d/e {}

const api = hap('/api', {})

api.example.hello({ name: "World" })
// POST /api/example/hello { "name": "World" }

Keywords

koa

FAQs

Package last updated on 20 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts