node.js - Learning Node & Express - 在 Post route not found 错误中难倒
问题描述
总的来说,我对 API 和 Web 开发领域非常陌生。我目前正在尝试将数据发布到我的代码中的假数据。
当我使用邮递员获取数据时,它可以工作。当我尝试发布数据时,出现 404 错误。
任何建议都会很棒..再一次,我对这一切都很陌生,所以请对这个婴儿编码器温柔一点。
const app = express();
const { v4: uuidv4 } = require("uuid");
const PORT = 3000;
//middleware
app.use(express.json());
let bountyHunter = [
{
firstName: "Dirty",
lastName: "Bubble",
living: true,
bountyAmount: 4000,
type: "Bubble",
_id: uuidv4(),
},
{
firstName: "Man",
lastName: "Ray",
living: true,
bountyAmount: 1000,
type: "Humanoid",
_id: uuidv4(),
},
{
firstName: "Sinister",
lastName: "Slug",
living: true,
bountyAmount: 500,
type: "Slug",
_id: uuidv4(),
},
];
//GET Route
app.get("/bountyHunter", (req, res) => {
res.send(bountyHunter);
});
//POST Route
app.post("/bountyHunter", (req, res) => {
res.send(`Successfully added to the database`);
});
// server startup logic
app.listen(PORT, () => {
console.log(`App started on port: ${PORT}`);
});```
解决方案
推荐阅读
- java - 如何使用 Rest 模板检索对象
- iis - 通过 localhost/文件夹访问另一台服务器上的 IIS 虚拟目录时出现运行时错误
- java - Spring Cloud - 在 Zuul 中使用 @LoadBalaneced RestTemplate
- ios - 触发UIDatePicker自动显示样式
- mongodb - 用户的 Mongo 聚合计数
- python - 如何在 pyinstaller 上包含资产,例如图像和音乐
- html - 为什么我不能在 HTML 中设置背景图像?
- javascript - 从 API json 多个 url 获取数据到 html 表中
- python - 使用Python在同一火花数据框中的两行之间减去数据
- javascript - d3.js 中的路径转换不起作用