Define and Use Next.js API Routes to Make Server Side Requests

Share this video with your friends

Send Tweet

Next.js is built on top of Node.js which means that you can define functions that will only run on the server. These functions are called API routes.

These API routes allow you to interact with 3rd party services, connect to the database, or use environment secrets without exposing any of that to the client. In short, they let you build out an API all inside of Next.js.

In this lesson, you’ll see how to fetch user data by id and return that data from an API route. You’ll learn about handling requests sent to the API route and what type of responses to send back to the client.