fetch(`http://10.58.0.37:8000/music/add/${props.id}`, {
method: "POST" ,
headers: {
Authorization: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Indsc3hvMjExMkBuYXZlci5jb20ifQ.i9ZWIGY6MUxYXcL344nsrwBiXD4hpvEavLGdYfaBSOs",
},
body: JSON.stringify({
music_id: props.mkList,
}),
})
.then(response => response.json())
.then(response =>
{
if(response.count === 0){
alert("이미 담은 곡입니다.");
}else if(response.count>=1){
alert(response.count+"곡이 담겼습니다.");
}
}
);
The example above is a full example on the use of the Fetch API;
Every fetch requires an API Address. The address above is in the shape of
`http://10.58.0.37:8000/music/add/${props.id}`
The http://10.58.0.37
section is the IP address of the API
:8000
is the port number
/music/add
is the end point
/${props.id}
refers to the url parameter. By adding a value at the end of the API address you can send additional info with the request.
/${props.id}
query strings can also be added to the end.More info on another blog
The API address tells the fetch method, which backend API to send the request to.