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
+10.7k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+6.4k Golang : Get UDP client IP address and differentiate clients by port number
+7.9k Golang : zlib compress file example
+9k Golang : Get HTTP protocol version example
+17.8k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+11.9k Golang : Check if IP address is version 4 or 6
+15k Golang : Archive directory with tar and gzip
+4.9k Golang : Convert source code to assembly language
+8.7k Golang : Convert(cast) uintptr to string example
+5.6k Swift : Convert (cast) String to Float
+7.5k Golang : Find and draw contours with OpenCV example
+5.6k Golang : Generate random Chinese, Japanese, Korean and other runes