Data Fetching

Learn about data fetching techniques in Next.js.

Fetching techniques in Next.js

Next.js allows us to fetch data on both the client and server sides. Server-side data fetching could happen in two different moments:

  • At build time using getStaticProps for static pages

  • At runtime using getServerSideProps for server-side rendered pages

Data can come from several resources: databases, search engines, external APIs, filesystems, and many other sources. Even if it’s technically possible for Next.js to access a database and query for specific data, we discourage that approach because Next.js should only care about the frontend of our application.

Get hands-on with 1200+ tech skills courses.