I am new in javscript development, and I have some trouble with passing id parameter in query URL. I am passing ID value in body now, which is not right, I guess in REST approach.
How can I pass Id: event.target.DepartmentId.value, into URL like https://localhost:5001/api/departments/{id} ?
handleSubmit(event){
event.preventDefault();
fetch("https://localhost:5001/api/departments/", {
method: "PUT",
headers:{
"Accept":"application/json",
"Content-Type":"application/json",
"Origin": "*"
},
body: JSON.stringify({
Id: event.target.DepartmentId.value,
Name: event.target.DepartmentName.value
})
})
.then(res=>res.json())
.then((result)=>
{
this.setState({snackbaropen: true, snackbarmsg: "Edited successfully!"})
},
(error) =>{
this.setState({snackbaropen: true, snackbarmsg: "failed"})
}
)
}
Thanks for any help!