This endpoint structures the APOD imagery and associated metadata so that it can be repurposed for other applications. In addition, if the concept_tags parameter is set to True, then keywords derived from the image explanation are returned. These keywords could be used as auto-generated hashtags for twitter or instagram feeds; but generally help with discoverability of relevant imagery
This is a community listing. If you own this API, you can request ownership.
npm install omnistream-sdkimport { OmniClient } from "omnistream-sdk";
const omni = new OmniClient({ token: process.env.OMNI_KEY! });
// One key reaches every API on the marketplace.
const data = await omni.call("nasa-apod/getapod");One install, one key - the same client calls every API on the marketplace.
Returns images
/**
* NASAAPOD - generated by OmniStream from NASA APOD's OpenAPI spec.
* One typed method per endpoint. A single Omni key reaches the API.
*/
const DEFAULT_BASE = "https://grid.skinvaults.online/v1/proxy/nasa-apod";
export class NASAAPODError extends Error {
status: number;
code?: string;
constructor(status: number, code: string | undefined, message?: string) {
super(message || `NASAAPOD error ${status}`);
this.name = "NASAAPODError";
this.status = status;
this.code = code;
}
}
export interface NASAAPODOptions {
baseUrl?: string;
fetch?: typeof fetch;
timeoutMs?: number;
}
export class NASAAPOD {
/** @param token Your OmniStream key (one key for every API). */
constructor(private token: string, private opts: NASAAPODOptions = {}) {
if (!token) throw new Error("NASAAPOD: token is required");
}
rateLimit: { remainingMinute?: number; remainingDay?: number } | null = null;
private async _request(method: string, path: string, { params, body }: { params?: Record<string, unknown>; body?: unknown } = {}): Promise<any> {
const f = this.opts.fetch ?? globalThis.fetch;
const url = new URL((this.opts.baseUrl ?? DEFAULT_BASE).replace(/\/+$/, "") + path);
if (params) for (const [k, v] of Object.entries(params)) if (v != null) url.searchParams.set(k, String(v));
const headers: Record<string, string> = { "x-omni-key": this.token };
if (body !== undefined) headers["content-type"] = "application/json";
const res = await f(url, { method, headers, body: body !== undefined ? JSON.stringify(body) : undefined });
this.rateLimit = {
remainingMinute: Number(res.headers.get("x-ratelimit-remaining-minute")) || undefined,
remainingDay: Number(res.headers.get("x-ratelimit-remaining-day")) || undefined,
};
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new NASAAPODError(res.status, data?.error?.code, data?.error?.message);
return data.data ?? data;
}
/** Returns images */
getapod(params: { "date"?: string; "hd"?: boolean }): Promise<any> {
return this._request("GET", "/apod", { params });
}
}
export default NASAAPOD;
No reviews yet. Be the first to rate this API.