DirectoryFast
  • 🚀Get Started
  • 🔤Tutorials
    • Bring me to life!
    • How it's structured?
    • Make it yours
    • Bonus
  • 🛠️Features
    • AI
      • AI URL Scanner & Scan Jobs
    • Analytics
    • Authentication
    • API
      • Protected Endpoints
    • Blog
    • Database
    • Emails
    • Error Pages
    • Icons
    • Payments
    • Private Pages
    • SEO
  • 📦General Components
    • Shadcn/ui Components
    • Navbar
    • Footer
    • SignIn Modal
    • Hero Section
    • Social Proof
    • Collections Social Proof
    • Featured Section
    • Latest Collections Section
    • Latest Products Section
    • Recommended Section
  • 📦Directory Components
    • Product Card
    • Collection Card
    • Product Note
    • Search Bar
    • Tags
    • Product Options Toggle
    • Combobox
    • Multi-Combobox
    • Submit Product
    • Feature Product
    • Manage Note
    • Manage Collection
    • Dashboard Tables
  • ⛓️Links
    • GitHub Repository
    • Support
Powered by GitBook
On this page
  • Structure
  • Calls
  1. Features

API

DirectoryFast is built on the latest NextJs features, including the App router.

PreviousAuthenticationNextProtected Endpoints

Last updated 11 months ago

Structure

All your "backend" stuff is located in the /api folder.

Any route.ts file will be an API endpoint, and the folder route will be the final API route. You can define dynamic content as well:

folder
url

/api/products

/products

/api/products/newest

/products/newest

/api/products/[slug]

/products/the-best-product

/api/category/[id]/products

/category/1337/products

Calls

API calls are handled by , a powerful and simple library that handle cache, background updates or stale data out of the box.

  • GET example:

const { isLoading: isUsersLoading, data: users } = useQuery({
    queryKey: [`users`],
    queryFn: async () => {
      const res = await fetch(`/api/users`);
      return res.json();
    },
  });
  • POST example:

const createMutation = useMutation({
    mutationFn: async (values) => {
      const res = await fetch("/api/categories", {
        method: "POST",
        body: JSON.stringify({
          ...values,
        }),
      });
      return res.json();
    },
  });
🛠️
Tanstack-Query