There are two approaches that you can set content-type
for a request.
header('Content-Type: application/json');
fetch('https://example/api', {
headers:{
'Content-Type': 'application/json',
},
I want to know, is setting the content-type
the duty of which developer? Backend or frontend? Or both of them? What's the standard way?
Both are correct and needed when working with two-sided communication. It's just some browsers/programs default their content type, so this is usually not required to implement because client programs send this already.
Sometimes applications only offer read-only resource so providing content-type is not necessary for the client, but is replied from the server side.
Providing the content type is also only required if the resource supports more than 1 content type, which is most often NOT the case.
So the answer, as it is often in software world is: "it depends" :)