Esempio di utilizzo dell'API REST di axe DevTools Linter

Link to Esempio di utilizzo dell'API REST di axe DevTools Linter copied to clipboard
Free Trial
Not for use with personal data

Questo articolo mostra un codice di esempio per accedere a axe DevTools Linter con curl e Python.

curl

L'esempio seguente mostra come utilizzare lo strumento da riga di comando curl per inviare richieste tramite 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 l'esempio sopra riportato con axe DevTools Linter SaaS, è necessario aggiungere la seguente opzione della riga di comando:

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

È inoltre necessario modificare l'opzione della riga di comando --url in:

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

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

Vedere Ottenimento di una chiave API per axe DevTools Linter SaaS per ulteriori informazioni su come ottenere una chiave API da utilizzare con axe DevTools Linter SaaS.

Python

L'esempio seguente mostra come accedere a 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 in modo che funzioni con axe DevTools Linter SaaS, è necessario ottenere una chiave API come descritto in Ottenimento di una chiave API per axe DevTools Linter SaaS e modificare baseUrl come segue:

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

Devi anche aggiungere la tua chiave API all'intestazione della richiesta modificando le intestazioni come segue:

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

Sostituisci LA TUA CHIAVE API con la chiave ottenuta in precedenza.