This is my server side code in PHP to update the supplier.
$app->put('/supplier/:id', function($id) use($app) {
// check for required params
verifyRequiredParams(array('name', 'mobile'));
$name = $app->request->put('name');
$mobile = $app->request->put('mobile');
$db = new DbHandler();
$response = array();
$result = $db->updateSupplier($id, $name, $mobile);
if ($result) {
$response["error"] = false;
$response["message"] = "Supplier updated successfully";
} else {
// supplier failed to update
$response["error"] = true;
$response["message"] = "Supplier failed to update. Please try again!";
}
echoRespnse(200, $response);
});
When I test this code with my rest client postman it works fine.
Now I want to use same API in my angular js application. This is my function for the same functionality.
var REST_SERVICE_URI2 = 'http://abcd.com/SupplierApi/v1/supplier/5';
function updateSupplier(supplier, id) {
̶v̶a̶r̶ ̶d̶e̶f̶e̶r̶r̶e̶d̶ ̶=̶ ̶$̶q̶.̶d̶e̶f̶e̶r̶(̶)̶;̶
var data = {
name: supplier.name,
mobile: supplier.mobile
};
͟r͟e͟t͟u͟r͟n͟ $http.put(REST_SERVICE_URI2, data)
.then(
function (response) {
̶d̶e̶f̶e̶r̶r̶e̶d̶.̶r̶e̶s̶o̶l̶v̶e̶(̶r̶e̶s̶p̶o̶n̶s̶e̶.̶d̶a̶t̶a̶)̶;̶
return response.data;
},
function(errResponse){
console.error('Error while updating Supplier');
̶d̶e̶f̶e̶r̶r̶e̶d̶.̶r̶e̶j̶e̶c̶t̶(̶e̶r̶r̶R̶e̶s̶p̶o̶n̶s̶e̶)̶;̶
throw errResponse;
}
);
̶r̶e̶t̶u̶r̶n̶ ̶d̶e̶f̶e̶r̶r̶e̶d̶.̶p̶r̶o̶m̶i̶s̶e̶;̶
}
The angular js code though is not able to update supplier. Is there anything wrong in my update function?