Vue.js / Nuxt.js

Nuxt Server Routes

API routes, server middleware, event handlers, H3, request/response, error handling, validation

20 câu hỏi phỏng vấn·
Mid-Level
1

In which directory should a file be created to expose an API route accessible at /api/users?

Câu trả lời

API routes in Nuxt are created in the server/api/ directory. Each file exporting an event handler automatically becomes accessible via /api/ followed by the file name. This convention allows for clear structuring of backend endpoints while benefiting from Nuxt's hot-reload and type-safety features.

2

Which function should be used to define an event handler in a Nuxt API route?

Câu trả lời

The defineEventHandler function is the main API for creating route handlers in Nuxt. It provides a typed event context that gives access to H3 utilities for manipulating requests and responses. This function replaces the older eventHandler API and offers better integration with Nuxt's type system.

3

What is H3 in the context of Nuxt server routes?

Câu trả lời

H3 is the minimalist HTTP framework that powers Nuxt's server engine. It provides a set of utilities for handling HTTP requests and responses efficiently and type-safely. H3 is designed to be lightweight, fast, and compatible with different runtime environments like Node.js, Workers, and Deno.

4

How to access query parameters in a Nuxt API route?

5

What is the correct file structure to create a dynamic API route /api/users/[id]?

+17 câu hỏi phỏng vấn

Nắm vững Vue.js / Nuxt.js cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí