Esempi di utilizzo dell'API REST di Axe DevTools Linter

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

Codice di esempio per accedere all'API REST di Axe DevTools Linter utilizzando curl e Python

Free Trial
Not for use with personal data

Questo articolo mostra del codice di esempio per accedere ad Axe DevTools Linter con curl e Python.

curl

L'esempio seguente mostra come utilizzare lo strumento da riga di comando curl per inviare richieste POST al server:

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"
}'

Per utilizzare il campione sopra con Axe DevTools Linter SaaS, è necessario aggiungere la seguente opzione da riga di comando:

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

È inoltre necessario modificare l'opzione da riga di comando --url come segue:

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

Il campione aggiornato per Axe DevTools Linter SaaS è il seguente:

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"
}'

Vedi Ottenere una chiave API SaaS di Axe DevTools Linter per ulteriori informazioni su come ottenere una chiave API per l'uso con Axe DevTools Linter SaaS.

Python

L'esempio seguente mostra come accedere ad Axe DevTools Linter utilizzando Python 3:

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)

Per modificare il precedente esempio Python per funzionare con Axe DevTools Linter SaaS, è necessario ottenere una chiave API come dettagliato in Ottenere una chiave API SaaS di Axe DevTools Linter e modificare baseUrl come segue:

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

È inoltre necessario aggiungere la propria chiave API all'header della richiesta modificando headers come segue:

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

Sostituisci LA TUA CHIAVE API con la chiave che hai ottenuto in precedenza.