BluemixのCloudant BDからデータを取得するためにJavaScript HTTPアダプタを使用しようとしています。そのために、私はTypeScriptでMFPF8とIonic2を使用しています。MobileFirst 8のJS HTTPアダプタでパラメータを追加
データベースから特定のドキュメントを取得する必要があるため、その名前を以前に知っていないため、ファイル名をパラメータとして送信できるHTTPアダプタが必要です。
私は、次のアダプタ実装ファイルがあります。
function getMenus() {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'menus/_all_docs?descending=true'
};
return MFP.Server.invokeHttp(input);
}
function getSpecificMenu(menuName) {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'menus/'+menuName
};
return MFP.Server.invokeHTTP(input);
}
そして、ここではそうadapter.xml
<mfp:adapter name="menus"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mfp="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>menus</displayName>
<description>menus</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>https</protocol>
<domain>bluemixcloudanthost.com</domain>
<port>443</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
<authentication>
<basic/>
<serverIdentity>
<username>user</username>
<password>pass</password>
</serverIdentity>
</authentication>
</connectionPolicy>
</connectivity>
<procedure name="getMenus" secured="false"/>
<procedure name="getSpecificMenu" secured="false"/>
</mfp:adapter>
で、APIドキュメントを、次の、私は私の中にアダプターを呼び出すために次のことをやりましたイオンプロバイダー
@Injectable()
export class MenuListingService {
data: any;
constructor() {
console.log('---> Constructing menu list adapter');
this.data = null;
}
load(menuTitle: string) {
console.log('---> Request '+menuTitle+' Menu');
if (this.data) {
// already loaded data
return Promise.resolve(this.data);
}
// don't have the data yet
return new Promise(resolve => {
let menuRequest = new WLResourceRequest("/adapters/menus/getSpecificMenu", WLResourceRequest.GET);
menuRequest.setQueryParameter('menuName', menuTitle);
menuRequest.send().then((response) => {
console.log('---> Current menu response received');
this.data = response.responseJSON.offers;
resolve(this.data);
})
});
}
}
知識センターで読むと、cal ?params = ['value']のようにクエリー文字列でパレメーターを照合しますが、500コードで失敗しています。
私はオフィスにいませんので、サーバーの応答とMFPサーバーのログエントリとともに、明日の編集を追加してすべての情報を追加します。
しかし、今のところ私がやったことに何か問題はありますか?
次のように、 'request.setQueryParameterValue(" ['value1'、 'value2'] '、forName: "params") 'とし、JavaScriptで' params'を処理します。アダプタ? https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/using-the-mfpf-sdk/resource-request/ios/#javascript-adapters –
Mhhh、私はそれを使用するオプションがありません方法。最後のファイルはタイスクリプトファイルで、私があなたが使っているものを見ているものから、速いものがあります。 –
私は何かを見逃しましたか?あなたのアプリはスウィフトアプリではありませんか? –