Basker Docs

Requests

How to send a FrontStage API query as a GET request, with the URL parameters it accepts

A FrontStage API request is an HTTP GET to https://<site-host>/graphql with the query in the URL. The host name selects the site. No API key or cookie is needed.

GET https://www.example.org/graphql?query={site{name}}&locale=es

URL parameters

ParameterRequiredDescription
queryYes, unless you send a known persisted query hashThe GraphQL query text.
variablesNoA JSON object with the values of the query variables, for example {"slug":"hamlet"}.
operationNameNoThe operation to run when query holds more than one named operation.
extensionsNoA JSON object. Use it to send a persisted query hash.
localeNoThe language of the response, for example es. Without it, the response uses the default language of the site. See Languages.

URL-encode each value. In JavaScript, URLSearchParams does this for you. With curl, use -G and --data-urlencode.

curl -s -G https://www.example.org/graphql \
  --data-urlencode 'query=query SiteName { site { name } } query Languages { site { locales { code } } }' \
  --data-urlencode 'operationName=Languages'

A query that holds more than one operation and has no operationName returns the error code OPERATION_RESOLUTION_FAILURE.

Send only GET requests

Basker caches a successful GET response at the edge. Every visitor who sends the same URL gets the cached response. To get the most cache hits:

  • Send the same query text for the same view. Remove extra whitespace and comments.
  • Write variables with the keys in the same order.
  • Do not add timestamps or random values to the URL.

The @baskerhq/frontstage-client package minifies the query and sorts the variable keys for you.

A POST request still works for existing callers, but Basker never caches it and can turn it off. Do not use POST in new code. The API rejects mutations.

Keep URLs short

Most CDNs and browsers refuse URLs longer than about 8,000 characters. The client throws an error before it sends a longer URL. To stay under the limit:

  • Use persisted queries. After the first request, the URL carries a 64-character hash in place of the query text.
  • Split a very large query into two or more queries.
  • Use fragments to reuse a selection in place of repeated fields.

Call the API from a browser

The API answers requests from any origin. Responses carry Access-Control-Allow-Origin: *. A GET request with only standard headers needs no preflight request. Do not send cookies or an Authorization header. A request with an Authorization header is never cached.

Responses

A response is JSON with data, errors, or both. A query that does not match the schema returns only errors:

{
  "errors": [
    {
      "message": "Cannot query field \"nope\" on type \"Site\". [Suggestion hidden]",
      "locations": [{ "line": 1, "column": 10 }],
      "extensions": { "code": "GRAPHQL_VALIDATION_FAILED" }
    }
  ]
}

Most GraphQL errors return HTTP status 200. Read the errors array, not only the status. See Limits and errors.

On this page