Next.js 构建后端 API

Next.js About 356 words

基于文件系统的路由

Next.jsApp Router是基于文件系统的路由,即:根据创建的文件夹名称来定义API的路径。

route.js

在文件夹中定义route.ts文件,编写GETPOST等请求方法。

代码

ResponseJavaScriptFetch API的接口。

export async function GET() {
    return Response.json({ message: 'Hello World' })
}

官方文档

https://nextjs.org/docs/app/api-reference/file-conventions/route

https://developer.mozilla.org/zh-CN/docs/Web/API/Response

Views: 12 · Posted: 2025-10-27

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Today In History
Browsing Refresh