Here’s a complete working example that fetches user details:
example.ts
import { fetchApi, isAnyErrorResponse } from 'rozod';import { getUsersUserdetails } from 'rozod/lib/endpoints/usersv1';// Fetch user details with full type safetyconst userInfo = await fetchApi(getUsersUserdetails, { userIds: [1, 123456] });if (isAnyErrorResponse(userInfo)) { console.error('Failed to fetch users:', userInfo.message); process.exit(1);}// TypeScript knows the exact structure of userInfo.datafor (const user of userInfo.data) { console.log(`User: ${user.displayName} (@${user.name})`); console.log(`Has verified badge: ${user.hasVerifiedBadge}`);}
Hover over variables in your IDE to see the inferred types. RoZod provides complete type information for all responses!
import { fetchApiPagesGenerator } from 'rozod';import { getGroupsGroupidWallPosts } from 'rozod/lib/endpoints/groupsv2';// Process pages as they arriveconst pages = fetchApiPagesGenerator( getGroupsGroupidWallPosts, { groupId: 11479637 });for await (const page of pages) { console.log(`Processing page with ${page.data.length} posts`); // Process this page's data for (const post of page.data) { console.log(`- ${post.body}`); }}
Use fetchApiPagesGenerator when working with large datasets to avoid loading everything into memory at once.
For server environments (Node.js, Bun, Deno), configure authentication once at startup:
import { configureServer, fetchApi } from 'rozod';import { getUsersUserdetails } from 'rozod/lib/endpoints/usersv1';// Configure once at startupconfigureServer({ cookies: 'your_roblosecurity_cookie_here'});// All subsequent requests automatically include the cookieconst userInfo = await fetchApi( getUsersUserdetails, { userIds: [123456] });
Never commit .ROBLOSECURITY cookies to version control. Use environment variables instead: