axe DevTools Linter REST API Example Usage

Link to axe DevTools Linter REST API Example Usage copied to clipboard
Free Trial

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

curl

The following example shows how to use the curl command line tool to POST requests to the 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"
}'

To use the above sample with axe DevTools Linter SaaS, you need to add the following command-line option:

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

You also need to change the --url command-line option to:

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

The sample updated for axe DevTools Linter SaaS is as follows:

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

See Obtaining an axe DevTools Linter SaaS API Key for more information about obtaining an API key for use with axe DevTools Linter SaaS.

Python

The following example shows how to access axe DevTools Linter using 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)

To change the previous Python sample to work with axe DevTools Linter SaaS, you need to obtain an API key as detailed in Obtaining an axe DevTools Linter SaaS API Key and change baseUrl as follows:

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

You also need to add your API key to the request header by changing headers to the following:

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

Replace YOUR API KEY with the key you obtained earlier.