Which content-type(MIME type) to use for JSON data
Problem :
Your program sitting in your web server is pumping out JSON data. You need to set the correct header Content-Type
or MIME type.
Which content-type should you use?
Solution :
For JSON:
Content-Type: application/json
Example data :
{ "Id": 1, "Name": "Boo", "Job": "CEO" }
For JSON-P and for passing a JavaScript object literal :
Content-Type: application/javascript
Example data :
functionCall({ "Id": 1, "Name": "Boo", "Job": "CEO" });
To set Header example in Golang :
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Type", "application/javascript")
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+9.8k Golang : How to check if a website is served via HTTPS
+16k Golang : Execute terminal command to remote machine example
+13.1k Golang : Image to ASCII art example
+4.8k Swift : Convert (cast) Float to Int or Int32 value
+7.6k Golang : Sort words with first uppercase letter
+8.8k Golang : Create and shuffle deck of cards example
+5.8k Golang : Dealing with backquote
+5.3k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+8.2k Android Studio : Import third-party library or package into Gradle Scripts
+21.6k Golang : Convert seconds to minutes and remainder seconds
+10.7k Golang : Web routing/multiplex example
+14.3k Golang : Find commonalities in two slices or arrays example