2017-08-17 18 views
1

私はAPI Gateway APIを作成しました。これをtypescriptで書いているnodejsプロジェクトから使いたいと思います。このために、私は生成されたSDKを含める必要があります。生成されたapiゲートウェイsdkをtypescript nodejsプロジェクトに含める方法

生成されたSDKは、何もエクスポートしないjsファイルで構成されています。例えば、メインのファイルは、「apigClient」は、基本的に次のようになります。

var apigClientFactory = {}; 
apigClientFactory.newClient = function (config) { 
... 
} 

はjavascriptのプロジェクトでこれを使用するためには、実行する必要があります:私は同じことを行うにはどうすればよい

<script type="text/javascript" src="apigClient.js"></script> 

をtypescriptで書かれたnodejsプロジェクト?

答えて

0

私は同じ問題を抱えています。

SDKはノードには適していません。ノードでSDKを使用するには、コードをモジュラーに変更する必要があります。

Node:aws-api-gateway-clientでAPIゲートウェイと通信できるライブラリが見つかりました。

NPM:https://www.npmjs.com/package/aws-api-gateway-client リポジトリ:https://github.com/kndt84/aws-api-gateway-client

しかし、このライブラリを、あなたが自分でリクエストを実装する必要があります。そこREADMEから適応:

// Require module 
 
var apigClientFactory = require('aws-api-gateway-client').default; 
 
// ES6: 
 
// import apigClientFactory from 'aws-api-gateway-client'; 
 
// Set invokeUrl to config and create a client. 
 
// For authorization, additional information is 
 
// required as explained below. 
 

 
// you can find the following url on 
 
// AWS Console/Gateway in the API Gateway Stage session 
 
config = {invokeUrl:'https://xxxxx.execute-api.us-east-1.amazonaws.com} 
 
var apigClient = apigClientFactory.newClient(config); 
 

 
// Calls to an API take the form outlined below. 
 
// Each API call returns a promise, that invokes 
 
// either a success and failure callback 
 

 
var params = { 
 
    //This is where any header, path, or querystring 
 
    // request params go. The key is the parameter 
 
    // named as defined in the API 
 
    userId: '1234', 
 
}; 
 
// Template syntax follows url-template 
 
// https://www.npmjs.com/package/url-template 
 
var pathTemplate = '/users/{userID}/profile' 
 
var method = 'GET'; 
 
var additionalParams = { 
 
    //If there are any unmodeled query parameters 
 
    // or headers that need to be sent with the request 
 
    // you can add them here 
 
    headers: { 
 
     param0: '', 
 
     param1: '' 
 
    }, 
 
    queryParams: { 
 
     param0: '', 
 
     param1: '' 
 
    } 
 
}; 
 
var body = { 
 
    //This is where you define the body of the request 
 
}; 
 

 
apigClient.invokeApi(params, pathTemplate, method, additionalParams, body) 
 
    .then(function(result){ 
 
     //This is where you would put a success callback 
 
    }).catch(function(result){ 
 
     //This is where you would put an error callback 
 
    });

私はこのことができます願っています。

関連する問題