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.
- In the Administration application, expand the Servers menu and click Advanced Configuration. Click I understand and accept the risk.
- Search for the Anzo REST API bundle and view its details.
- Click the Services tab and expand Anzo REST API.
- Locate the org.openanzo.servlet.allowCrossOriginAccess property (shown in the image below).
- Click the property to make it editable, and then change
false
totrue
. - Click the checkmark icon (
) for that property to save the change.
- 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}; } }