[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"

相关推荐
前端_yu小白35 分钟前
js异步机制
前端·javascript·async·promise·await·js异步·回调地狱
Spider Cat 蜘蛛猫35 分钟前
chrome extension开发框架WXT之WXT Storage api解析【补充说明一】
前端·javascript·chrome
程序猿John4 小时前
ES6 新增特性 箭头函数
前端·javascript·es6
百锦再5 小时前
五种常用的web加密算法
前端·算法·前端框架·web·加密·机密
@大迁世界5 小时前
彻底改变我 React 开发方式的组件模式
前端·javascript·react.js·前端框架·ecmascript
William Dawson6 小时前
【Vue 3 + Element Plus 实现产品标签的动态添加、删除与回显】
前端·javascript·vue.js
拉不动的猪6 小时前
项目基础搭建时的一些基本注意点
前端·javascript·面试
蕉君桑6 小时前
vue2使用vue-echarts
前端·vue.js·echarts
runnerdancer6 小时前
React+Vite+Typescript项目脚手架模版
前端
Code额7 小时前
ECMAScript 6 新特性(二)
前端·javascript·ecmascript