0
0
Expressframework~10 mins

Documenting endpoints in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Express library.

Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Aexpress
Bhttp
Crouter
Dendpoint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express'
Using 'router' which is part of Express but not the main import
2fill in blank
medium

Complete the code to create a new Express app instance.

Express
const app = [1]();
Drag options to blanks, or click blank then click option'
Aexpress
Brouter
Crequire
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'router()' which is for routing, not app creation
Using 'listen()' which starts the server, not creates the app
3fill in blank
hard

Fix the error in the route definition to respond with 'Hello World'.

Express
app.get('/hello', (req, res) => {
  res.[1]('Hello World');
});
Drag options to blanks, or click blank then click option'
Ajson
Bwrite
Csend
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.write which does not end the response
Using res.json which sends JSON, not plain text
4fill in blank
hard

Fill both blanks to document the GET endpoint with Swagger.

Express
/**
 * @swagger
 * /users:
 *   [1]:
 *     description: Get all users
 *     responses:
 *       200:
 *         description: Success
 */
Drag options to blanks, or click blank then click option'
Aput
Bget
Cdelete
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase HTTP methods
Using wrong HTTP verbs like post or put
5fill in blank
hard

Fill all three blanks to add a Swagger parameter for user ID in the path.

Express
/**
 * @swagger
 * /users/{id}:
 *   get:
 *     parameters:
 *       - in: [1]
 *         name: [2]
 *         required: true
 *         schema:
 *           type: [3]
 */
Drag options to blanks, or click blank then click option'
Apath
Bquery
Cid
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' instead of 'path' for path parameters
Using wrong parameter name or type