PUTリクエストをエンドポイントに送信したいのですがElasticSearchインデックスを作成します。そのためにAxios NPMモジュールを使用します。データとカスタムヘッダーを使用して、さまざまなREST動詞の要求を送信する方法を教えてください。
const options = {
hostname: "c1-es03c.aue2l.internal",
port: 9200,
path: "/",
method: "PUT",
rejectUnauthorized: true,
requestCert: true,
servername: "c1-elasticsearch.internal",
ca: [fs.readFileSync("./Root-CA.pem")],
headers: {
"Authorization": "Basic xxxxx"
}
req.write("{data here}");
req.end();
var req = https.request(options, callback)
HTTPSモジュールは問題なく動作しますが、どうやってaxiosやrequestで同じことができますか。
axios.put(url、options、data)が機能しませんでした。
回答:
回答№1は0あなたは "$ npm install axios"コマンドを使ってaxiosをインストールすることができます。このタイプスクリプトコードで簡単に理解できます。詳しくはこちらのリンクをご覧ください。 Axios npm
const axios = require("axios");
export class RequestContext {
constructor() { }
post(request: any, response: any): void {
let header = {
"Content-type": "application/json"
}
let data = request.data;
axios.put(url, data, header).then((result) => {
\ .then() methord is use when you want to process on data that return from API.
console.log(result)
})
}
}