i'm trying to use fetch delete request method to delete item in my localhost server using react redux
method to call
deleteItem(e) {
e.preventDefault();
const id = this.props.id;
this.props.deleteSet(id);
}
Dispatching the action
const mapDispatchToProps = dispatch => ({
deleteSet: id => dispatch(deleteSet(id)),
});
Action
export function deleteSetSuccess(id) {
return {
type: "DELETE_SET_SUCCESS",
id,
};
}
export function deleteSet(data) {
return (dispatch) => {
fetch(`${apiUrl}orgs/1/sets/${data}`, {
method: "DELETE",
body: JSON.stringify(data),
headers: new Headers({
"Content-Type": "application/json",
}),
}).then(response => response)
.then(id => dispatch(deleteSetSuccess(id)));
};
}
Reducer
export function deleteSetSuccess(state = '', action) {
switch (action.type) {
case "DELETE_SET_SUCCESS":
return action.id;
default:
return state;
}
}
response from the localhost server
DELETE http://localhost:8080/distinction-2.0-alpha2/api/orgs/1/sets/8 400 (Bad Request)