Postman POST request not sending

Its probably an error with my API, but I couldn’t find anything wrong with it at all. Postman just loads forever and never sends the POST, until I click cancel and my API terminal prints:

POST /api/backend/categories - - - - ms


So I guess its some sort of timeout? I’m VERY new to programming so I don’t even know if this post should go here or somewhere like stack exchange.

Hey @pbhacking :waving_hand:

Welcome to the Postman Community! :postman:

What’s the implementation for that POST route? Are you getting the same for each of your endpoints?

Without knowing what it’s doing on the code side, it’s tough to know why it’s taking taking that long.

Do you just want a screenshot of my API code? Or just the router endpoints?

Edit: For now, the Categories is the only API with a POST method, so I couldn’t test with another till I added it

The code of that POST route, it could be doing or waiting for anything? Do you get the same if you run the request from the terminal using curl?

I haven’t tried using curl yet, here’s the code:

console.log(`Registering route: ${apiurl}/categories`);
const categoryRouter = require('./routers/categories.js');
console.log(`Categories router loaded!`);

categories.js:

const {Category} = require('../schemas/category'); // Import the Category model
const express = require('express');
const router = express.Router();


router.get(`/`,async (req, res) => {
    const categoryList = await Category.find();
    if (!categoryList) {
        return res.status(404).json({ message: 'No Categories found or available, or an API error. The website may not be able to access the Categories right now, and you may have to wait for a fix.' });
    }
  res.send(categoryList);
})

router.post(`/`, async (req, res) => {
    let category = new Category({
      name: req.body.name,
      typeof: req.body.typeof,
      payment: req.body.payment,
      age: req.body.age,
      difficulty: req.body.difficulty,
      location: req.body.location,
      duration: req.body.duration,
      dateNtime: req.body.dateNtime,
      skills: req.body.skills,
      reoccurring: req.body.reoccurring,
      urgency: req.body.urgency,
      minimumRating: req.body.minimumRating,
      icon: req.body.icon,
      color: req.body.color, 

    })
    
    category = await category.save();
    
    if (!category) {
      return res.status(404).json({ message: 'Could not POST. this is likely due to a client error and we suggest you deal with it lmao.' });
  }
})




module.exports = router;

And What would I run to send the same request from terminal?

Update: It turns out the POST IS sent, but my API doesn’t recognize so. In MongoDB the Schedule does show up, but both my API and Postman are still waiting, so would it be an API error?


I fixed it. It was an error on my end, and a stupid one at that. Turns out I forgot

res.send(category);

in the categories.js


But thanks for your help @danny-dainton, I really appreciate it!

1 Like

You’re welcome - It’s always good to debug these things with another person, most of the time you see the issue straight away.

We’re always here if you need us! :heart: