Vue.js / Nuxt.js

Nuxt Server Routes

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

20 คำถามสัมภาษณ์·
Mid-Level
1

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

คำตอบ

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?

คำตอบ

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?

คำตอบ

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 คำถามสัมภาษณ์

เชี่ยวชาญ Vue.js / Nuxt.js สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี