Data Fetching

You can fetch data from other pages using snatcher().

#snatcher()

'snatch' does not fetch data through http, but directly accesses the file and fetch data.

Typescript
import { snatcher } from 'zely';
 
export async function get(req, res) {
  const snatch = snatcher(req, res);
  const { body } = await snatch(/*PATH*/, /*METHOD*/);
}

You can also use it directly through req.snatch without calling snatcher.

Typescript
export async function get(req, res) {
  const { body } = await req.snatch('/user');
 
  res.send(`users: ${body}`);
}

#Example

pages/index.ts
import { snatcher } from 'zely';
 
export async function get(req, res) {
  const snatch = snatcher(req, res);
  const { body } = await snatch('/user');
 
  res.send(`users: ${body}`);
}
pages/users.ts
export function get(req, res) {
  res.json({ cat: '🐱' });
}

:::