DEV Community

Nisal-Sashmitha
Nisal-Sashmitha

Posted on

How to make a get request using axios with params and read it in backend.

Let's see how to make a get request using axios with params and read the request and get params in backend.

FrontEnd

//take 'docID' as the id of the ducement you search
//take port number as 4200

axios
      .get("http://localhost:4200/api/stock/getProduct", {
        params: { id: docID },
      })
      .then(function (response) {
        console.log(response.data);
      })
      .catch(function (error) {
        console.log(error);
      })
      .then(function () {
        // run anything after the response is arrived
      });
Enter fullscreen mode Exit fullscreen mode

Backend

const router = express.Router();

router.get("/getCusProducts", getProduct);

function getProduct(req, res) {
  let id = req.query.id; //<<<this is how you read params

  Product.findById(id)    // Product is the model
    .then((product) => {
      res.json(product);
    })
    .catch((err) => {
      console.log(err);
    });
}
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more