Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have below code which is working fine for GET and POST but not for PUT in node js. I am using method overloading for GET and PUT. Below is my app.js code.

import { Router } from 'express';
const AuthRoutes = Router();
const AppRoutes = Router();
AuthRoutes.get('/customer/:customername', getCustomerbyname);
AuthRoutes.post('/calculate/:id', calculate);
AuthRoutes.put('/customer/:customername', saveCustomer);


Here my GET and POST is working fine but for PUT its giving me error. Below URL I am trying for PUT.

>https://domainname/customer/abc

I dont know what I am missing here.

>Error - You don't have permission to access /domainname/customer/abc

Can you please help me if I am missing something here.Basically I am trying to do a PUT request by providing customer name in URL and other details in BODY section of request. So if customer with name exist, it will update it otherwise create it newly.

What I have tried:

Not sure why exactly this error. GET and POST is working fine.
Posted
Updated 24-Feb-20 23:03pm
v3
Comments
Telstra 24-Feb-20 11:40am    
Even if now I have changed PUT url to saveCustomer but still same error.
Kris Lantz 25-Feb-20 10:56am    
Doesn't each type of request require the respective permission to do so? Have you verified that you have the permission to PUT?
Telstra 25-Feb-20 11:06am    
So far I was doing only GET and POST. This is first service I am doing with PUT. I am following same code flow except change in HTTP verb. Still it says no permission. Do I need to install any NPM package for PUT
Kris Lantz 25-Feb-20 11:15am    
There's no new packages to grab, and the verbage change from POST to PUT is usually the requirement, but I seem to recall that (in the little bit of web dev I did in college) that the account making the request had to have explicit permissions.
Telstra 25-Feb-20 11:22am    
That account has a permission. Because it is already posting a data to service with no issues. Only PUT is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900