[NextJs 14] Summarize data fetching architecture

Introduction

In this article, I am gonna summarize the modes about data fetching in NextJs for better understanding of NextJs.

API Router Mode

Tranditionally,we use fetch or axios tool to request data by HTTP-Request.

This mode, meanwhile, is supposed to offer api to outside world in public.

However, when you use fetch-api in Server Component,that obviously is inapproriate. Because why fecthing api in the same place. In Server Component, we can directly call the function service from server.

Server Component Call Service Mode

In Server Component, we can call the service function from server, at the same time,remain the api ability in public.

Client Component Call Service Mode

In Client Component, we can't call the service function from server directly. because, the service does not exist in Client Side. But, we can continue to use api router mode.

If we want to do this, we should mark service file as "use server"

相关推荐
都在酒里8 分钟前
STM32 Bootloader 实战:RS-485 固件升级与断电恢复
javascript·stm32·嵌入式硬件
JudithHuang1 小时前
Vue3 Vitest 单元测试进阶
前端·单元测试·log4j·vue
费曼学习法2 小时前
把 Agent 可观测性做进 Harness:从日志里只有 task finished 到全链路回放
前端
GuWenyue2 小时前
z-index 写到 9999 还是被盖住:把层叠上下文的 6 个反例全复现了一遍
前端·css·浏览器
htzyl2062 小时前
TypeScript:tsconfig配置误区及详情介绍,让你清清楚楚
前端·typescript
不服老的小黑哥2 小时前
0b · M2:服务化 + SSE 流式
前端
梦曦i2 小时前
0.9.0 新增页面级 style 支持
前端·uni-app x
不服老的小黑哥2 小时前
10a · M1:命令行 Agent
前端
疯华整猫2 小时前
类型全对、tsc 零错误,上线却白屏:AI 时代学 TypeScript,学的是它替不了的那一层
前端·typescript
Hilaku2 小时前
2027制药业4大ERP选型参考:主流厂商对比与优缺点分析
前端·javascript·程序员