JigsawStack can be easily integrated into Next.js API routes. Here’s an example of a web-search API endpoint:
pages/api/web-search.ts
Copy
import type { NextApiRequest, NextApiResponse } from "next";import { JigsawStack } from "jigsawstack";const jigsawstack = JigsawStack(); // API key will be read from environmentexport default async (req: NextApiRequest, res: NextApiResponse) => { try { const result = await jigsawstack.web.search({ query: "What is the capital of France?", }); res.status(200).json({ results: result.results, }); console.log(result); } catch (error) { return res.status(400).json(error); }};
For client components that need to use JigsawStack, you should make requests through your API routes rather than directly from the client to protect your API key.