当我在Postman中尝试URL时出现此错误。我不知道问题出在哪里。
getBook(bookName):此方法返回该名称的书
这就是我在邮递员中发布URL的方式
https://localhost:32244/api/books?name=Specification通过示例
应用类
route.get('/api/books?name=bookName',async (req , res) =>{
const book= repoacc.getBook(req.params.bookName)
res.send(book)
})
路线课程
const express = require('express')
const route = express()
const bodyParser = require('body-parser')
const repoacc = require('./repositories/BookRepo.js')
route.get('/', (req , res) =>{
res.send("welcome")
})
route.get('/api/books/:bookName',async (req , res) =>{
const book= repoacc.getBook(req.params.bookName)
res.send(book)
})
答案 0 :(得分:0)
在应用类中,您必须正确定义路由参数bookName
:
route.get('/api/books?name=:bookName',async (req , res) => {
const book = repoacc.getBook(req.params.bookName);
res.send(book);
});