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
+8.8k Golang : Inject/embed Javascript before sending out to browser example
+12.7k Golang : http.Get example
+21.1k Golang : How to get time zone and load different time zone?
+10.8k Golang : Sieve of Eratosthenes algorithm
+6.5k Golang : Warp text string by number of characters or runes example
+8k Golang : Multiplexer with net/http and map
+5.3k Gogland : Datasource explorer
+9.3k Golang : Play .WAV file from command line
+5.8k Facebook : How to force facebook to scrape latest URL link data?
+3.5k Java : Get FX sentiment from website example
+18.4k Golang : Send email with attachment
+7.7k Golang : Load DSA public key from file example