Recall & Review
beginner
What is an API route in Next.js?
An API route is a special file inside the 'app/api' folder that handles HTTP requests like GET or POST. It runs on the server and lets you create backend endpoints easily within your Next.js app.
Click to reveal answer
beginner
What are server actions in Next.js?
Server actions are functions that run on the server and can be called directly from client components. They simplify server communication by avoiding separate API endpoints and letting you handle server logic inline.
Click to reveal answer
intermediate
When should you choose API routes over server actions?
Choose API routes when you need a RESTful or external API, want to share endpoints with other apps, or need fine control over HTTP methods and headers.
Click to reveal answer
intermediate
What are the benefits of using server actions instead of API routes?
Server actions reduce boilerplate code, improve developer experience by calling server code directly, and help keep client and server logic close together for simpler apps.
Click to reveal answer
intermediate
Can server actions replace all API routes in Next.js?
No. Server actions are great for internal server logic but API routes are still needed for public APIs, external integrations, or when you want to expose endpoints outside your app.
Click to reveal answer
Which Next.js feature lets you create backend endpoints with HTTP methods?
✗ Incorrect
API routes handle HTTP requests like GET and POST, acting as backend endpoints.
What is a key advantage of server actions over API routes?
✗ Incorrect
Server actions let you call server code directly from client components without separate endpoints.
When should you prefer API routes instead of server actions?
✗ Incorrect
API routes are best for public or external APIs accessible outside your app.
Which Next.js feature improves developer experience by reducing boilerplate for server calls?
✗ Incorrect
Server actions simplify calling server logic directly, reducing boilerplate.
Can server actions handle all use cases of API routes?
✗ Incorrect
Server actions are not suitable for public or external APIs; API routes are needed there.
Explain the main differences between API routes and server actions in Next.js.
Think about how each handles server logic and when to use them.
You got /4 concepts.
Describe a scenario where you would choose API routes over server actions and why.
Consider if your server code needs to be accessed outside your Next.js app.
You got /4 concepts.