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
+30k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+4.8k Linux : Disable and enable IPv4 forwarding
+4.1k Golang : Convert lines of string into list for delete and insert operation
+14.7k Golang : Update database with GORM example
+5.3k Golang : How to get capacity of a slice or array?
+4k Google : Block or disable caching of your website content
+7.7k Golang : Combine slices but preserve order example
+17.3k Golang : Write file with io.WriteString
+6.6k Golang : Shuffle strings array
+33.9k Golang : Save image to PNG, JPEG or GIF format.
+7.1k Golang : Variadic function arguments sanity check example
+9.2k Golang : Text file editor (accept input from screen and save to file)