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
+29.7k Golang : Login(Authenticate) with Facebook example
+23.3k Golang : Randomly pick an item from a slice/array example
+7.9k Golang : Mapping Iban to Dunging alphabets
+8.4k Prevent Write failed: Broken pipe problem during ssh session with screen command
+5.4k Golang : Customize scanner.Scanner to treat dash as part of identifier
+22.3k Golang : Match strings by wildcard patterns with filepath.Match() function
+21.9k Golang : How to reverse slice or array elements order
+5.6k Golang : PGX CopyFrom to insert rows into Postgres database
+7.2k Golang : Gargish-English language translator
+13.2k Golang : Calculate elapsed years or months since a date
+14.9k Golang : Normalize unicode strings for comparison purpose
+20.9k Golang : Secure(TLS) connection between server and client