0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Azure】AzureTranslatorのAPIをVSCodeから叩く

Last updated at Posted at 2022-12-20

概要

ウェブ開発でAzure Translatorを使う機会があり、検証としてAPIをローカルから叩きたかった。

前提条件

  • Azureの開発環境があること
  • VSCodeがインストールされていること

事前準備

  • Azure PortalでTranslatorをデプロイ
    • リソース作成はこちらの記事を参照
    • デプロイ完了後、リソースに移動し、キーとエンドポイントにてキー1・地域を控えておく
  • VS Codeで拡張機能をインストール

HTTPリクエスト用ファイル作成

以下の.httpファイルを作成

POST https://api.cognitive.microsofttranslator.com/translate/
    ?api-version=3.0
    &from=ja
    &to=en
    &to=ko
content-type: application/json
Accept: application/json
Ocp-Apim-Subscription-Key:{キー1}
Ocp-Apim-Subscription-Region:{地域}

[{
    "Text":"{翻訳したい文章}"
}]

クエリパラメータにて、fromで翻訳元言語、toで翻訳先言語を指定する
翻訳先言語は複数指定可能

リクエストの送信

POSTの上あたりにSend Requestというボタンが出てくるので押下
image.png

横のタブに結果が返ってくる
image.png

その他参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?