Learn key principles and practical steps in creating a REST API using Node.js and Express.js, from environment setup to handling requests. This quiz covers essential concepts like routes, HTTP verbs, and CRUD operations for beginners in backend development.
Which principle ensures that each client request to a REST API contains all information needed for the server to process it without relying on stored context?
Explanation: Statelessness requires each request to be self-contained, which is a core REST concept. Stateful Connection is the opposite and not a REST principle. Strict Typing relates to programming languages, not REST. Synchronous Execution pertains to how code runs but isn't directly related to REST architecture.
What is the main purpose of running 'npm init -y' when starting a Node.js REST API project?
Explanation: 'npm init -y' quickly creates a package.json file, initializing the project with default settings. It does not install Express.js, start a server, or set up a database—these tasks require separate commands.
After setting up an Express.js server on port 3000, what output appears in the terminal when it starts successfully?
Explanation: A successful start on port 3000 displays 'Server running on http://localhost:3000'. The other options do not match the intended port or indicate errors rather than successful startup.
Which HTTP method is typically used to create a new resource in a REST API?
Explanation: POST is the standard HTTP verb for creating new resources. GET retrieves resources, DELETE removes them, and PATCH is commonly used for partial updates. Only POST is used for creation.
What functionality does 'app.use(express.json())' provide in an Express-based REST API?
Explanation: 'app.use(express.json())' middleware parses JSON payloads in incoming requests. It does not open database connections, perform URL routing, or validate data beyond parsing JSON structure.