0

I am VERY new to the world of API and web development in general. I'm currently trying to post data to fake data I have in my code.

When I use postman to GET the data, it works. When I try to POST the data, I get a 404 error.

Any advice would be great..again, I am VERY new to all of this so please be gentle with this baby coder.

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}`);
});```

0 Answers0