All Tracks/quiz introduction to express/
Đang tải...
Hướng dẫn thử thách
1 / 1

Introduction to Express Quiz

To pass the quiz, you must correctly answer at least 18 of the 20 questions below. # --quizzes-- ## --quiz-- ### --question-- #### --text-- What is the relationship between an API and a web service? #### --distractors-- Every API is a web service, but not every web service is an API. --- APIs and web services are identical concepts. --- Web services only work with REST, while APIs support multiple protocols. #### --answer-- Every web service is an API, but not every API is a web service. ### --question-- #### --text-- Which HTTP header does a client use to tell the server which response format it wants? #### --distractors-- `Content-Type` --- `Authorization` --- `X-Requested-With` #### --answer-- `Accept` ### --question-- #### --text-- What does statelessness mean in a REST architecture? #### --distractors-- The server stores the client's session data between requests. --- The client keeps no state of its own across requests. --- REST restricts all requests to read-only operations. #### --answer-- The server stores no memory of previous requests. ### --question-- #### --text-- Which REST HTTP method is used to remove a resource? #### --distractors-- `GET` --- `POST` --- `PUT` #### --answer-- `DELETE` ### --question-- #### --text-- What is a key advantage of microservices over a monolith? #### --distractors-- Simpler debugging and fewer network calls between services. --- A single shared codebase that all teams contribute to. --- Easier infrastructure management across all services. #### --answer-- Faster development, better fault isolation, and the ability to use different languages per service. ### --question-- #### --text-- What does calling `express()` return? #### --distractors-- A new HTTP server. --- A router object. --- A middleware function. #### --answer-- A new instance of Express application. ### --question-- #### --text-- What is middleware in Express? #### --distractors-- A built-in method used to start the Express server. --- A special type of HTTP method used in REST APIs. --- A built-in tool for serving static files from a directory. #### --answer-- Code that runs between receiving a request and sending a response. ### --question-- #### --text-- What does `app.listen(port, callback)` do in Express? #### --distractors-- Defines a route for incoming requests. --- Loads the Express library. --- Creates a new middleware function. #### --answer-- Starts the server and begins listening for incoming HTTP requests. ### --question-- #### --text-- What is a route parameter in Express? #### --distractors-- A fixed URL path like `/home`. --- A query string appended to the URL. --- A method for serving static files. #### --answer-- A placeholder in the URL prefixed with `:` that captures a dynamic value. ### --question-- #### --text-- How do you access the dynamic value captured from a URL like `/post/42` in an Express route defined as `/post/:postId`? #### --distractors-- `req.query.postId` --- `req.body.postId` --- `req.url.postId` #### --answer-- `req.params.postId` ### --question-- #### --text-- What does `res.json()` do in Express? #### --distractors-- Sends a plain text response. --- Redirects the client to a different URL. --- Renders a template engine view and sends the resulting HTML. #### --answer-- Sends a JSON response and automatically converts a JavaScript object. ### --question-- #### --text-- What does `res.redirect(url)` do in Express? #### --distractors-- Sets the HTTP status code. --- Sends a JSON response. --- Renders a view using a template engine. #### --answer-- Redirects the client to a different URL. ### --question-- #### --text-- What is the purpose of `app.route()` in Express? #### --distractors-- To create a new instance of the Express application. --- To serve static files from a specified directory. --- To define separate routes for different URL paths. #### --answer-- To chain multiple HTTP method handlers for the same path in one block. ### --question-- #### --text-- What does `express.Router()` create? #### --distractors-- A new Express application instance that replaces `app` for handling all server logic. --- A middleware function dedicated to catching and handling route-level errors. --- A built-in static file server that automatically maps files to URL paths. #### --answer-- A router object, similar to a mini Express app, that you define routes on and mount in the main application. ### --question-- #### --text-- How do you mount a router in the main Express app? #### --distractors-- By calling `router.listen()`. --- By calling `router.start()`. --- By calling `app.get()` directly inside the router. #### --answer-- By calling `app.use(path, router)`. ### --question-- #### --text-- Which built-in Express middleware is used to serve static files? #### --distractors-- `express.json()` --- `express.urlencoded()` --- `express.raw()` #### --answer-- `express.static()` ### --question-- #### --text-- What happens when a user requests a static file that does not exist in the directory configured with `express.static()`? #### --distractors-- Express throws an error and crashes the server. --- Express redirects the user to the home page. --- Express creates an empty file at the requested path. #### --answer-- Express automatically responds with a 404. ### --question-- #### --text-- Which of the following is true about SOAP compared to REST? #### --distractors-- SOAP uses JSON and is more flexible than REST, making it ideal for modern applications. --- SOAP is the most widely used web service type today, having replaced REST in most systems. --- SOAP supports multiple response formats, including plain text, JSON, and binary data. #### --answer-- SOAP uses only XML and is common in enterprise systems that need stricter standards and security. ### --question-- #### --text-- What is a route handler in Express? #### --distractors-- A configuration object that maps all available route paths to their HTTP methods. --- A middleware function that automatically intercepts and serves static files from a folder. --- A database connector that processes and handles route-related database queries. #### --answer-- A callback function that runs when a request matches a route, with access to `req` and `res`. ### --question-- #### --text-- What is a benefit of using `express.Router()` instead of defining all routes directly in `app.js`? #### --distractors-- It allows the server to handle significantly more concurrent HTTP requests at once. --- It automatically generates and registers REST API endpoints based on route file names. --- It lets the server start and run without needing to specify a port number. #### --answer-- It separates concerns and keeps the main file clean by moving related routes into their own modules.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.sql
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵
Test Output
Thử thách này không có bài test tự động. Hãy quan sát kết quả trực tiếp ở khung Preview.