npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hyper-api-client

v2.5.3

Published

A hyper-schema API client

Downloads

8

Readme

hyper-api-client

Install

npm install hyper-api-client --save

Usage

Config compiler and create instance AppApiClint

import HyperApiClient from 'hyper-api-client'
import Ajv from 'ajv'
import 'whatwg-fetch'

function initAPIClient() {
  HyperApiClient.compiler = function () {
    return new Ajv()
  }

  var doRequest = function ({method, url, data}) {
    return fetch(url, {
      method,
      body: JSON.stringify(data)
    })
  }

  return HyperApiClient.createClient({
    doRequest: doRequest
  })
}

let AppApiClint = initAPIClient()

export default AppApiClint

Add schema to AppApiClint

let findUserSchema = {
  href: 'http://domain.com/api',
  title: 'findUser',
  method: 'post',
  description: 'Find user by name',
  definitions: {
    name: {
      type: 'string'
    },
    age: {
      type: 'number'
    }
  },
  schema: {
    properties: {
      name: {
        type: 'string'
      }
    }
  },
  targetSchema: {
    properties: {
      name: {
        $ref: '#/definitions/name',
      },
      age: {
        $ref: '#/definitions/age'      
      }
    }
  }
}

AppApiClint.addSchema(findUserSchema)

Use directly

AppApiClint.findUser.send({name: 'hal.zhong'}).then(user => {
  console.info(user.name)
})

Install vue-modello plugin

import VueModello from 'vue-modello'
import HyperApiClient from 'hyper-api-client'
import AppApiClient from './api_client'

let AppModello = new VueModello()
AppModello.use(HyperApiClient.VueModelloPlugin, {
  client: AppApiClient
})

if (top !== window) {
  let loc = location
  top.href.replace(loc.domain + (loc.port || '') + '//' + loc.hostname + '/#')
}

vue-modello plugin Option

| OptionName | Type | Example | Description | |--------------------------------|----------|-----------|-------------| | client | Object | | HyperApiClient instance | | disableResultValidate | Boolean | false | 默认值为 false,为 true 时将不校验响应结果 | | suppressResultInvalidError | Boolean | false | 默认值为 false,为 true 时将不会在响应结果校验出错时抛出错误 | | disableParametersValidate | Boolean | false | 默认值为 false,为 true 时将不校验请求参数 | | suppressParametersInvalidError | Boolean | false | 默认值为 false,为 true 时将不会在请求参数校验出错时抛出错误 | | onError | Function | fn(error) | |

vue modello hyper api plugin mix option

| Property | Priority | Type | Default | Example | Description | | --------------------------- | -------- | -------- | ------- | --------------------- | ----------------------------- | | parameter | | Object 或 String | {} | | 'parameterPath' 等价于 { valuePath: 'parameterPath' } | | parameter.valuePath | | String | | 'query' | 请求参数在 state 中的 path,将根据它自动设置参数的其他选项 | | parameter.set | + | Function | | fn(state, value) |提供一个函数设置参数的值,用于将 schema 中的默认值复制给参数 | | parameter.get | + | Function | | fn(state) | 提供一个函数从 state 中获取参数,仅用于发起请求时未传递参数 | | parameter.validateEnabled | | Boolean | true | | watch parameters and validate 通过 vue-modello 的 watch 选项监听参数变化并进行校验 | | parameter.validateErrorPath | | String | | 'validateError.query' | 参数校验错误的保存到 state 的 path | | parameter.setValidateError | + | Function | | fn(state, error, propPath) | 提供一个函数保存参数校验错误 | | parameter.copyDefault | | Boolean | | | Be true if valuePath present 是否 copy schema 中的默认值到参数 | | result | | Object 或 String | {} | | 'resultPath' 等价于 { valuePath: 'resultPath'} | | result.valuePath | | String | | 'list' | 保存结果到 state 的 path | | result.set | + | Function | | fn(state, value) | 用于保存响应结果到 state | | result.filter | | Function | | fn(result) | filter result 用于通过校验后过滤响应结果 | | result.copyDefault | | Boolean | | | Be true if valuePath present 是否复制默认值到响应结果 |

Add api to model

let UserModel = {
  modelName: 'User',

  hyperApi: {
    findUser: {}
  },

  actions: {

  },

  mutations: {

  }
}