egg-aliyun-api-gateway

1.0.1 • Public • Published

egg-aliyun-api-gateway

NPM version build status Test coverage David deps Known Vulnerabilities npm download

egg plugin for aliyun-api-gateway

Install

$ npm i egg-aliyun-api-gateway --save

Usage

  • GET
app.aliyunApiGateway.get(url)
  • POST
app.aliyunApiGateway.post(url, data)

Configuration

// {app_root}/config/plugin.js
exports.aliyunApiGateway = {
  enable: true,
  package: 'egg-aliyun-api-gateway',
};
// {app_root}/config/config.default.js
exports.aliyunApiGateway = {
  appKey: '',
  appSecret: '',
};

see config/config.default.js for more detail.

Example

  • Generator
'use strict';

module.exports = app => {
  return class HomeController extends app.Controller {
    * get() {
      const { ctx, app } = this;
      const url = 'https://openapi.insta360.com/community/v1/dailySelection/list?date=2017-07-16&days=1';
      try {
        ctx.body = yield app.aliyunApiGateway.get(url);
      } catch (error) {
        ctx.status = 400;
        ctx.body = error.toString();
      }
    }

    * post() {
      const { ctx, app } = this;
      const url = 'https://openapi.insta360.com/community/v1/post/update';
      const data = {
        id: {id},
        info: {info},
      };
      try {
        ctx.body = yield app.aliyunApiGateway.post(url, data);
      } catch (error) {
        ctx.status = 400;
        ctx.body = error.toString();
      }
    }

  };
};
  • Async
'use strict';

module.exports = app => {
  return class HomeController extends app.Controller {
    async get() {
      const { ctx, app } = this;
      const url = 'https://openapi.insta360.com/community/v1/dailySelection/list?date=2017-07-16&days=1';
      try {
        ctx.body = await app.aliyunApiGateway.get(url);
      } catch (error) {
        ctx.status = 400;
        ctx.body = error.toString();
      }
    }

    async post() {
      const { ctx, app } = this;
      const url = 'https://openapi.insta360.com/community/v1/post/update';
      const data = {
        id: {id},
        info: {info},
      };
      try {
        ctx.body = await app.aliyunApiGateway.post(url, data);
      } catch (error) {
        ctx.status = 400;
        ctx.body = error.toString();
      }
    }

  };
};

Feature

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-aliyun-api-gateway

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • thonatos