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

vue-api-creator

v2.0.5

Published

An api manager bases on Vue

Downloads

41

Readme

vue-api-creator

Build Status Coverage Status codebeat badge

An api manager bases on axios

中文文档

Usage

Install

npm install vue-api-creator -S
import api from './api'
import ApiCreator from 'vue-api-creator'

Vue.use(ApiCreator, {
  baseURL: '/baseURL'
  modules: api,
  // Response fails if response status is in this list
  permanentErrors: [404, 415, 500, 501, 429],
  beforeRequest (options) {
    console.log(options)
  },
  afterRequest (res) {
    console.log(res)
  },
  onError (err) {
    if (err.isInternalError) {
      console.log('An exception has occurred on your network')
    } else {
      console.log('An error response from server')
    }
  },
  mock: 'https://www.xxxx.com'
})

Use

export default {
    created () {
        this.$api('app/list').then(res => {
            // ....
        }).catch(err => {
            // ....
        })
    }
}

Api directory

├──  api
│    │── app
│    │    ├── index.js
│    └── index.js   

app/index.js

export default {
    BASE_URL: '/sys/app',
    api: [
      {
        name: 'list',
        desc: 'get apps',
        method: 'GET',
        path: 'list',
        mock: true // enable mock
      }
    ]
}

api/index.js

import app from './app'

export default {
    app
}

Server Response Structure

Your server response body shoule be like this:

{
  code: Number, // status code
  success: Boolean, // whether the response was successful 
  msg: String, // response message
  data: <T> // response data
}

Configuration

ApiCreator config

  • baseURL: The base URL of the request. (String or Function)
  • modules: Api modules.
  • axios: axios instance.
  • enableEncodeURIComponent: encodes characters using EncodeURIComponent.
  • permanentErrors: Response fails if response status is in this list, default: [404, 415, 500, 501, 429].
  • beforeRequest: Called before the request is sent.
  • afterRequest: Called after the request was received.
  • onError: An error occurred during send request or server response, eg: status code in permanentErrors, the request was made but no response was received...
  • mock: The base URL of the mock server.

Api config

  • name: It is api's name.
  • desc: The description of the api.
  • method: The request method to be used when making the request.
  • path: It is the server URL that will be used for the request.
  • mock: Enable mock to the request.
  • params: query params (Array or Boolean). eg: params: ['id', 'name'] => /api/xxxx?id=1&name=2
  • body: body params (Array or Boolean). eg: body: ['ids', 'names'] => {ids: [1], names: ['a', 'b']}
  • responseType: response type. accepted values: ['', 'arraybuffer', 'blob', 'document', 'json', 'text']. default: json

License

MIT

Copyright © 2019, msidolphin