Connect to Galaxy
Connect to a Galaxy instance for API access.
Galaxy Charts plugins are developed standalone, outside of any running Galaxy server. To pull datasets, metadata, or run jobs, the plugin needs to connect to a Galaxy API.
Provide two environment variables when starting the dev server to connect to a Galaxy instance:
GALAXY_KEY: Your Galaxy API key.GALAXY_ROOT: The Galaxy server URL e.g.https://usegalaxy.orgfor Galaxy main.
Run the following command, replacing MY_API_KEY and MY_GALAXY_SERVER with your own values:
GALAXY_KEY=MY_API_KEY GALAXY_ROOT=MY_GALAXY_SERVER npm run dev
Making Requests to the Galaxy API
Galaxy Charts UI provides GalaxyApi, a small wrapper around the Galaxy API:
import { GalaxyApi } from "galaxy-charts";
async function fetchGalaxyVersion() {
try {
const { response, data } = await GalaxyApi().GET("/api/version");
console.log("API Version:", data);
} catch (error) {
console.error("Error fetching Galaxy version:", error);
}
}
GalaxyApi supports GET, POST and PUT requests.
Direct API Requests with Fetch
Plugins not using Galaxy Charts UI can call the Galaxy API directly with fetch. For example, a GET request:
async function fetchGalaxyVersion() {
try {
const response = await fetch("/api/version", {
credentials: process.env.credentials || "include",
headers: { "Content-Type": "application/json" },
method: "GET",
});
const data = await response.json();
console.log("API Version:", data);
} catch (error) {
console.error("Error fetching Galaxy version:", error);
}
}
How to Obtain an API Key
- Go to your Galaxy instance and sign in.
- Click on your username in the top navigation bar, then select Preferences.
- Scroll down to the Manage API Key section to create and access your personal API key.