Enabling Cross-Origin Resource Sharing

By default, cross-origin resource sharing (CORS) is disabled for the Graph Studio REST API service. If you plan to access the API from a web client and need to enable cross-origin requests, follow the steps below.

  1. In the Administration application, expand the Servers menu and click Advanced Configuration. Click I understand and accept the risk.
  2. Search for the Anzo REST API bundle and view its details.
  3. Click the Services tab and expand Anzo REST API.
  4. Locate the org.openanzo.servlet.allowCrossOriginAccess property (shown in the image below).

  5. Click the property to make it editable, and then change false to true.

  6. Click the checkmark icon () for that property to save the change.
  7. Restart Graph Studio to apply the configuration change.

The Graph Studio API service is now configured to allow cross-origin requests. As an example of a CORS request, the following snippet from a React application reloads a graphmart via an API call. The request retrieves an authorization token and configures an Axios request object with the token and CORS-related headers:

export default async function reloadAnzo() {
  const authorization = getAnzoAuth(); //basicAuth
  console.log('Authorization', authorization);
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: authorization,
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Credentials': true,
      'Access-Control-Allow-Methods': 'POST, OPTIONS',
    },
  };
  const url =
    'https://{{AnzoURL}}/api/v1/graphmarts/{{GraphmartIRI}}/reload';
  try {
    const success = await axios.post(url, config);
    console.log('return', success);
    return success;
  } catch (error) {
    console.log(error);
    return {error};
  }
}