• Blog
  • Documentation
  • Courses
  • Changelog
  • AI Starters
  • UI Kit
  • FAQ
  • Supamode
    New
  • Pricing

Launch your next SaaS in record time with Makerkit, a React SaaS Boilerplate for Next.js and Supabase.

Makerkit is a product of Makerkit Pte Ltd (registered in the Republic of Singapore)Company Registration No: 202407149CFor support or inquiries, please contact us

About
  • FAQ
  • Contact
  • Verify your Discord
  • Consultation
  • Open Source
  • Become an Affiliate
Product
  • Documentation
  • Blog
  • Changelog
  • UI Blocks
  • Figma UI Kit
  • AI SaaS Starters
License
  • Activate License
  • Upgrade License
  • Invite Member
Legal
  • Terms of License
    • Reactfire
    • useCurrentOrganization
    • useCurrentUserRole
    • useIsSubscriptionActive
    • useUserSession
    • withAppProps
    • withTranslationProps
    • withAuthProps
    • withPipe
    • withMethodsGuard
    • withAuthedUser
    • withExceptionFilter
    • withCsrf

withPipe

The "withPipe" is a utility function that helps you pipe functions when handling API requests.

API Routes have several utilities that help you build your API endpoints, and save you from writing boilerplate code.

1. withPipe: piping functions when handling API requests

The withPipe function is used to pipe functions when handling API requests.

ts
import { NextApiRequest,NextApiResponse } from "next";
import { withAuthedUser } from '~/core/middleware/with-authed-user';
import { withPipe } from '~/core/middleware/with-pipe';
import { withMethodsGuard } from '~/core/middleware/with-methods-guard';
import { withExceptionFilter } from '~/core/middleware/with-exception-filter';
export default function helloWorld(
req: NextApiRequest,
res: NextApiResponse
) {
const handler = withPipe(
withMethodsGuard(['GET']),
withAuthedUser,
(req, res) => {
res.status(200).json({ message: 'Hello World!' });
}
);
return withExceptionFilter(req, res)(handler);
}

This helps you write the utility functions we will see next in a more readable way.