Axe DevTools Linter REST API 使用例

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

curlとPythonを使用したAxe DevTools Linter REST APIへのアクセスの例コード

Free Trial
Not for use with personal data

This article shows example code for accessing Axe DevTools Linter with curl and Python.

curl

次の例では、curlコマンドラインツールを使用してサーバーにリクエストをPOSTする方法を示します:

curl --request POST \
  --url http://localhost:3000/lint-source \
  --header 'Content-Type: application/json' \
  --data '{
        "source":"import React from \"react\";const testing = (props) => {    return (        <div>            <button tabIndex={5}>{props.name}</button>            <button tabIndex={5}>{props.name}</button>            <button tabIndex=\"5\">{props.name}</button>        </div>    );}\nexport default testing;",
        "filename": "string.js"
}'

上記のサンプルを Axe DevTools Linter SaaS で使用するには、次のコマンドラインオプションを追加する必要があります。

--header 'Authorization: <YOUR API KEY>' \

また、--urlコマンドラインオプションを次のように変更する必要があります:

--url https://axe-linter.deque.com/lint-source

Axe DevTools Linter SaaS 用に更新したサンプルは以下の通りです。

curl --request POST \
  --url https://axe-linter.deque.com/lint-source \
  --header 'Content-Type: application/json' \
  --header 'Authorization: <YOUR API KEY>' \
  --data '{
        "source":"import React from \"react\";const testing = (props) => {    return (        <div>            <button tabIndex={5}>{props.name}</button>            <button tabIndex={5}>{props.name}</button>            <button tabIndex=\"5\">{props.name}</button>        </div>    );}\nexport default testing;",
        "filename": "string.js"
}'

Axe DevTools Linter SaaSで使用するAPIキーの取得についての詳細は、Axe DevTools Linter SaaS API キーの取得を参照してください。

Python

次の例は、Python 3 を使用して Axe DevTools Linter にアクセスする方法を示しています。

import requests

baseUrl = "http://localhost:3000/lint-source"

headers = {
      "Content-Type": "application/json"
      }

data = {
  "source": "# Heading\n\n### Another Heading\n",
  "filename": "file.md"
     }

response = requests.post(baseUrl, json=data, headers=headers)

print(response.text)

Axe DevTools Linter SaaSで動作するように前のPythonサンプルを変更するには、Axe DevTools Linter SaaS API キーの取得に記載されている通りにAPIキーを取得し、baseUrlを次のように変更する必要があります:

baseUrl = "https://axe-linter.deque.com/lint-source"

リクエストヘッダーにAPIキーを追加するために、headersを次のように変更する必要があります:

headers = {
      "Content-Type": "application/json",
      "Authorization": "YOUR API KEY"
      }

先ほど取得したキーでYOUR API KEYを置き換えてください。