Next.js App Router
This guide walks through integrating SyncSnap in a Next.js app using the App Router: API route, React components, and styling.1. Install dependencies
@syncsnap/react):
2. Configure environment
Create or update.env.local with your SyncSnap API key (get it from the dashboard):
syncsnap server SDK reads this to authenticate with the SyncSnap API. Do not expose it to the client.
3. Create the SyncSnap API route
The React SDK expects a backend that can create jobs, return job status, and return presigned download URLs. Thesyncsnap package provides a Next.js handler that implements all of this with one catch-all route.
Create the file:
app/api/syncsnap/[...syncsnap]/route.ts
- POST for
POST /api/syncsnap/job(create job) - GET for:
GET /api/syncsnap/job/:id(get job)GET /api/syncsnap/job/:id/wait(server waits until job completes; returns{ job, result? }; query:timeoutMs,intervalMs)GET /api/syncsnap/job/:id/download(get presigned download URL; optional?expiration=15)
[...syncsnap] (e.g. job, jobId, download).
4. Use the React components
In any client page or component, use the upload button and optional callbacks:5. Add styles
Import the SDK theme so the button and dialog look correct. In your root layout or global CSS (e.g.app/globals.css):
Tailwind v4:
content including node_modules/@syncsnap/react), then:
6. Custom API base path
If you mount the SyncSnap API under a different path, pass the URLs into the hook used by the button (or intouseSyncsnapJob directly):
createJobUrl: "/api/syncsnap/job", getJobUrl(id) => "/api/syncsnap/job/" + id, and getWaitForCompletionUrl(id) => getJobUrl(id) + "/wait".
Summary
- Install
@syncsnap/reactandsyncsnap, setSYNCSNAP_TOKEN. - Add one catch-all route with
createRouteHandler({ client }). - Use
SyncsnapUploadButtonin a client component and import the SDK theme. - Optionally customize
createJobUrl,getJobUrl,getWaitForCompletionUrl, andqrBaseUrl.