Connect any JavaScript website
Use @atmyapp/core with Next.js, SvelteKit, Nuxt, Remix, a Node server or plain browser code.
Open with AI
@atmyapp/core reads content in any JavaScript runtime with fetch: Node 18+, edge runtimes, and browsers. Your framework keeps doing routing, rendering and caching; AtMyApp supplies the data.
Using Astro? Follow the Astro tutorial instead. The integration does steps 4 and 6 for you, and adds previews, SEO tags and forms.
1. Get your keys
Section titled “1. Get your keys”In the dashboard, create a project, then copy:
- from Settings → API keys: the Project API URL (
https://edge.atmyapp.com/v0/projects/<id>) and an API key, - from Settings → CLI keys: the
atmyapp use …command.
The API key is public and safe in browser code. The CLI key is not. Keys and URLs explains the difference.
2. Install
Section titled “2. Install”npm install @atmyapp/core @atmyapp/structurenpm install --save-dev @atmyapp/clipnpm add @atmyapp/core @atmyapp/structurepnpm add --save-dev @atmyapp/cliyarn add @atmyapp/core @atmyapp/structureyarn add --dev @atmyapp/cliThen connect the CLI with the command from Settings → CLI keys:
npx atmyapp use --url https://api.atmyapp.com/v0/projects/<id> --token <cli-key>3. Write and upload a schema
Section titled “3. Write and upload a schema”Create atmyapp.schema.ts in the project root:
import { defineCollection, defineDocument, defineSchema, s } from "@atmyapp/structure";
export default defineSchema({ definitions: { home: defineDocument({ fields: { headline: s.string({ max: 80, description: "Main homepage heading." }), intro: s.longText({ optional: true }), }, }), posts: defineCollection({ fields: { title: s.string(), slug: s.slug({ source: "title" }), excerpt: s.string({ max: 200 }), cover: s.image({ optional: true }), }, }), },});Upload it:
npx atmyapp migrateThen add a homepage and a post or two in the dashboard, and publish them. Websites read published content only, except in previews.
4. Create the client
Section titled “4. Create the client”Make one module that creates the client from your environment. Core does not read environment variables itself, so pass the values in:
import { createAtMyAppClient } from "@atmyapp/core";import schema from "../../atmyapp.schema";
export const ama = createAtMyAppClient({ baseUrl: process.env.ATMYAPP_API_URL!, apiKey: process.env.ATMYAPP_API_KEY!, schema, errorPolicy: "throw",});ATMYAPP_API_URL=https://edge.atmyapp.com/v0/projects/<id>ATMYAPP_API_KEY=<api-key>schemamakes reads typed:getValue("home")knows aboutheadline, andlist("posts")returns posts.errorPolicy: "throw"makes a failed read throw. The default,"quiet-empty", logs a warning and returns empty values. That keeps a browser widget alive, but it can also hide a broken setup or ship an empty static page.
5. Read content in your framework
Section titled “5. Read content in your framework”import { ama } from "@/lib/atmyapp";
export const revalidate = 60; // refresh published content at most once a minute
export default async function Home() { const home = await ama.storage.getValue("home"); const posts = await ama.collections.list("posts", { limit: 10 });
return ( <main> <h1>{home.headline}</h1> {posts.map((post) => ( <a key={post.slug} href={`/blog/${post.slug}`}>{post.title}</a> ))} </main> );}Server Components run on the server, so process.env works and the reads never reach the browser.
import { createAtMyAppClient } from "@atmyapp/core";import { ATMYAPP_API_URL, ATMYAPP_API_KEY } from "$env/static/private";import schema from "../../../atmyapp.schema";
export const ama = createAtMyAppClient({ baseUrl: ATMYAPP_API_URL, apiKey: ATMYAPP_API_KEY, schema, errorPolicy: "throw",});import { ama } from "$lib/server/atmyapp";
export const load = async () => ({ home: await ama.storage.getValue("home"), posts: await ama.collections.list("posts", { limit: 10 }),});<script lang="ts"> let { data } = $props();</script>
<h1>{data.home.headline}</h1>{#each data.posts as post} <a href="/blog/{post.slug}">{post.title}</a>{/each}import { createAtMyAppClient } from "@atmyapp/core";import schema from "~~/atmyapp.schema";
export const ama = createAtMyAppClient({ baseUrl: process.env.ATMYAPP_API_URL!, apiKey: process.env.ATMYAPP_API_KEY!, schema, errorPolicy: "throw",});export default defineEventHandler(() => ama.storage.getValue("home"));<script setup lang="ts">const { data: home } = await useFetch("/api/home");</script>
<template> <h1>{{ home?.headline }}</h1></template>import { createAtMyAppClient } from "@atmyapp/core";import schema from "../atmyapp.schema";
const ama = createAtMyAppClient({ baseUrl: import.meta.env.VITE_ATMYAPP_API_URL, apiKey: import.meta.env.VITE_ATMYAPP_API_KEY, schema,});
const home = await ama.storage.getValue("home");document.querySelector("h1")!.textContent = home.headline;The API key is public, so it’s fine in a bundle. In the browser, keep the default quiet-empty policy, or catch errors, so one failed read doesn’t break the page.
Set content with textContent or your framework’s normal text binding. Text fields are plain text, not trusted HTML.
6. Choose when content refreshes
Section titled “6. Choose when content refreshes”| How you render | When published edits appear | What to do |
|---|---|---|
| Static build (SSG) | After the next build | Rebuild on publish. AtMyApp hosting does this for you; elsewhere, see Deploy. |
| Server rendering | On the next request | Responses may be cached for up to 60 seconds. Use your framework’s caching (revalidate, Cache-Control) for the rest. |
| Browser | On the next read | Nothing. Reads may be cached for up to 60 seconds. |
For static builds, keep errorPolicy: "throw" so a failed read fails the build instead of publishing empty pages.
7. Add previews (server rendering only)
Section titled “7. Add previews (server rendering only)”When your client clicks Preview, AtMyApp opens your page with ?amaPreviewKey=… in the URL. To show drafts, create a client per request with that key:
import { createAtMyAppClient } from "@atmyapp/core";import schema from "../../atmyapp.schema";
export function amaForRequest(url: URL) { const previewKey = url.searchParams.get("amaPreviewKey") ?? undefined; return createAtMyAppClient({ baseUrl: process.env.ATMYAPP_API_URL!, apiKey: process.env.ATMYAPP_API_KEY!, schema, previewKey, mode: previewKey ? "priority" : "client", errorPolicy: "throw", });}Never store a preview key in a shared, module-level client, and never cache a preview response publicly. Drafts and previews covers the details.
- Documents and media: every way to read a document, image or file.
- Collections: filters, pagination and sorting.
- Forms on any website: collect submissions without a backend.
@atmyapp/corereference: every option and method.
