Ask An SEO
A. ..

Ask An SEO: SaaS (SEO-as-a-Service)

Ask An SEO is an open source API. Any search engine optimisation related question can be posed and an honest answer will be returned as JSON.

This site was created as a learning resource for APIs for Chris Johnson's BrightonSEO April 2020 talk, Mastering The API and Having Fun Along The Way.

API

The endpoint for this API is https://api.askanseo.dev/ and will accept GET and POST requests.

The API is hosted as a Google Cloud Function any may take a second or two to respond on the first query.

GET

For GET requests the question should be sent as a question parameter in the querystring.

Example: ?question=Is%20*%20a%20ranking%20factor?

CURL

A simple GET request using cURL.

curl https://api.askanseo.dev/?question=Is%20*%20a%20ranking%20factor?"

PYTHON

A simple Python3 GET example using the Requests library.

import requests

question = 'Is * a ranking factor?'

response = requests.get('https://api.askanseo.dev/?question=' + question)
# Returns true if a valid 200 response was sent.
if response:
    # Print the JSON output.
    print(response.json())
else:
    # We didn't receive a valid 200 response. Handle the error.
    print(response.status_code)

JAVASCRIPT

A simple JavaScript GET example using the Fetch API.

const question = 'Is * a ranking factor?';

fetch('https://api.askanseo.dev/?question=' + question)
    .then(response => {
        // Throw an error if we didn't receive a valid 200 response.
        if (!response.ok) {
            throw Error(response.status);
        }

        // If we received a valid 200 response then pass on the JSON data.
        return response.json();
    })
    .then(json => {
        // Print the JSON output.
        console.log(json);
    })
    .catch(error => {
        // We didn't receive a valid 200 response. Handle the error.
        console.log(error)
    });

POST

For POST requests should be sent as a JSON payload with question as the name, and the question as the value.

Example: {"question": "Is * a ranking factor?"}

CURL

A simple POST request using cURL.

curl -X POST https://api.askanseo.dev/ -d '{"question":"Is * a ranking factor?"}' -H "Content-Type: application/json"

PYTHON

A simple Python3 POST example using the Requests library.

import requests

request = {'question': 'Is * a ranking factor?'}
response = requests.post('https://api.askanseo.dev/', json=request)

# Returns true if a valid 200 response was sent.
if response:
    # Print the JSON output.
    print(response.json())
else:
    # We didn't receive a valid 200 response. Handle our error.
    print(response.status_code)

JAVASCRIPT

A simple JavaScript POST example using the Fetch API.

const question = 'Is * a ranking factor?';
const request = {"question": question};

fetch('https://api.askanseo.dev/', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(request)
    })
    .then(response => {
        // Throw an error if we didn't receive a valid 200 response.
        if (!response.ok) {
            throw Error(response.status);
        }

        // If we received a valid 200 response then pass on the JSON data.
        return response.json();
    })
    .then(json => {
        // Print the JSON output.
        console.log(json);
    })
    .catch(error => {
        // We didn't receive a valid 200 response. Handle the error.
        console.log(error)
    });

RESPONSE

Below is a sample response, in JSON:

{
    "question": "<YOUR QUESTION>"
    "answer": "<HONEST ANSWER>"
}

GITHUB

If you wish to contribute further the source code for the Google Cloud Function and this basic frontend website can be found on Github:

Ask An SEO API - Google Cloud Function

Ask An SEO API - Frontend

CONTACT

If you have any questions I can be found on Twitter: @defaced