egg-aliyun-api-gateway
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.jsexportsaliyunApiGateway = enable: true package: 'egg-aliyun-api-gateway';
// {app_root}/config/config.default.jsexportsaliyunApiGateway = 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.