
该视频仅会员有权观看
立即开通课程「Node 框架 Express 实践」权限。
Summary:
- A new interface to fetch comments on the screen is defined in the comment controller.
- The processor for the interface is imported at the top of the file from comment service within the current directory.
- A processor named "index" is defined to execute the function
get comments, which retrieves a list of comments and sends it to the client.
- This is enclosed in a try-catch block, with the try block declaring a variable
comments to store the result of get comments.
- The response is sent back to the client using
response.send with the retrieved comments data.
- Errors are handled in the catch block using
next to pass the error to the application's error handler.
- The comment route is defined in the comment router with method
get at the route /comment, linked to the index handler in the comment controller.
- The interface is tested with an HTTP client by creating a request named "comments list request" using the HTTP GET method to the URL
api/comment.
- The server response contains all the comments in the application.