Using axios as a client in express.js to send and receive parameters via the Delete method

I have encountered a problem with my API in express js for a DELETE request. The API checks for a password parameter before proceeding with other tasks. Interestingly, this setup works perfectly fine when tested locally on postman, but fails to work with the hosted server on heroku.

Below is a snippet from my API code:

  ...
 if (!req.body.password) {
   return res.status(400).json({ message: "Please input the password"})
  }
  ...

On the client side, I am using:

axios.delete('url/id', ({password: 'password'}))
 .then()
 .catch()

The issue lies in the fact that req.body.password is not being recognized and is showing up as undefined on the hosted server.

Answer №1

It is not a usual practice to include data in the body of a delete request, making it distinct from post, put, and patch requests. You can find more information about this here

To perform a delete request correctly, follow this format:

axios.delete('/some/uri', { data: 'my delete body' })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is the AJAX form submitting back to its own page?

I'm experiencing some issues with AJAX on my website tonight. After submitting a form, the page refreshes with the values in the URL instead of performing the AJAX request. I have a validate plugin with a submit handler in place, but it doesn't s ...

Accessing an array within a function from a separate .JS file

Currently, I am facing a somewhat awkward predicament where I have a function in main.js that requires an array that is populated in second.js... In simple terms, the function in main.js is designed to be reusable: function chug() { p1.innerHTML = st ...

Passport local auth along with passport mongoose local do not support using email addresses as usernames

I have been experimenting with the passport local strategy and passport mongoose local to handle user authentication. Initially, I used the default username method but now I am trying to switch to using email instead. However, after following the documenta ...

Unique browsing key

Is there a specific identifier that can uniquely represent the browser you are currently using? I have two applications logged in through ApiGateWay, and I need to determine whether they are both running on the same browser. Therefore, I require a unique ...

Analyzing Development Environment Metrics in Google Analytics 4

Is there a way to automatically filter out pageviews from localhost without having to manually create custom reports? I want to track developer traffic, but I don't want it to skew my data. In GA4, there are currently two options to filter out develo ...

What does the "listen EACCESS localhost" error in the code signify and why is it occurring?

const express = require('express'); const morgan = require('morgan'); const host = 'localhost'; const port = 3000; const app = express(); app.use(morgan('dev')); app.use(express.static(__dirname + '/public&ap ...

Tips for retrieving an object using a key in javascript or typescript when the key is unknown

Could someone help me figure out how to access the 'value' key in this object? { '-L7uAVxXmuLeBN1K-B0_': { timestamp: '18:35:18', value: 19.81 } } I'm not familiar with the first key, '-L7uAVxXmuLeBN1K-B0_', b ...

Is there a way to access data from a different cart template containing personalized values on Shopify?

After analyzing the values required from product.json, I realized that the current method is not efficient. The client-side ends up processing unnecessary information and every new product or option adds to the request load. Below is the script responsible ...

Is there a method in Node.js Express/Connect to manipulate the session to have an indefinite duration?

This is my current approach: app.use(express.session({ cookie:{domain:"."+settings.c.SITE_DOMAIN}, secret:'abc', store: redis_store, })); Upon checking my redis and running TTL se ...

Uncovering the characteristics of a GeoJSON data layer within Google Maps V3

Is there a way to access the properties of the data layer itself when loading a geoJSON file into a Google Map? I understand how to access the individual properties like posts_here, but I'm interested in obtaining the properties for the layer as a wh ...

The jQuery ajax function functions flawlessly on a local environment, but encounters issues when used on a

After spending the entire day researching this issue, it appears to be a common problem without a solution in sight. The challenge I am facing involves using jquery's $.ajax() function to update database values through a service call. While it works ...

Patience is key when waiting for another get request to finish in Node.js HTTP

I am facing a challenge where I need to send a file via HTTP and then report any errors that occur during the process. To tackle this issue, I have set up my Express server like so: const app = express(); app.get('/download', async(req, res) => ...

Jquery refuses to conceal a particular element

I've encountered this issue before, but I'm facing a problem this time. I'm attempting to create a popup that is initially hidden. When clicked, the popup does appear, but I'm unable to close it. Additionally, when trying to change the ...

The replace method for strings in JavaScript does not function properly on mobile devices

I encountered an issue with the string replace method I implemented on my website. Upon checking the page using the web browser on my Android phone, I noticed that it was not functioning as intended. Here's a snippet of the code: /*The function is ...

Changes are being made to how Date objects stored in Firestore behave, which could potentially cause disruptions in your app

Currently encountering an issue while working on VueJs where I am struggling to log data from Firebase. Despite making code adjustments based on the console's recommendations, nothing seems to be working as expected. My setup involves using Vue Cli 3 ...

The watch functionality is failing to work within a specialized attribute directive that is being utilized within a separate custom element directive

I'm currently working with two directives that handle separate functionalities. I am attempting to utilize the attribute directive within an element directive, but I'm encountering issues with the watch function not working on the attribute direc ...

Building an HTML form to generate an array of objects by collecting form data

Hey there, I'm working on an HTML form in React that utilizes form action and FormData. However, when I extract the formData using my method, it shows a structure like this: https://i.stack.imgur.com/nzgLX.png My goal is to have an array of objects ...

Having trouble loading a base64 image into a React component using webpack

In my images folder, I've created a file called b64Images.js which contains the following: export const placeholder = "data:image/png;base64,longb64string" I'm attempting to import this file into one of my react components using: import { plac ...

Encountering a reload error while refreshing the Angular page

Whenever I click on a deck from my list, the corresponding deck-detail component is supposed to load and display the details of the selected deck. The URL should also change to something like "deck/id/deckName". However, if I try to reload the page or copy ...

How can I prevent the interpolation of "${variable}" in HTML when using AngularJS?

I need to display the string ${date} in a div element: <div>please substitute the ${date} as the tag for the name</div> The displayed content should be: please use the ${date} as the substitute tag to the name. However, the browser interpre ...