cs531-f19 / discussions

Discussions board for CS 431/531 Web Server Design course
2 stars 12 forks source link

Wrong API MIME Type #83

Open ibnesayeed opened 4 years ago

ibnesayeed commented 4 years ago

Find an "in the wild" examples of an API with a MIME type of application/json that should be something else and suggest what the MIME type should be.

Neyo-odu commented 4 years ago

curl -i -X OPTIONS https://www.pinterest.com/ HTTP/1.1 405 Method Not Allowed content-type: application/json allow: GET, POST, HEAD, DELETE x-envoy-upstream-service-time: 1 set-cookie: _routing_id="52e16908-d8cd-4fb8-b5c3-9f2163b505a7"; Max-Age=86400; Path=/; HttpOnly x-pinterest-rid: 3843363079112262 Content-Length: 62 Date: Thu, 12 Dec 2019 04:13:48 GMT Connection: keep-alive X-CDN: fastly Pinterest-Generated-By: coreapp-webapp-prod-0a01c065

I would suggest this be text/html or text/plain

ibnesayeed commented 4 years ago

@Neyo-odu 1) this is not an API and 2) it indeed is returning a JSON response.

$ curl -i -X OPTIONS https://www.pinterest.com/
HTTP/2 405 
content-type: application/json
content-length: 62
allow: GET, POST, HEAD, DELETE
pinterest-generated-by: coreapp-webapp-prod-0a018824
pinterest-generated-by: coreapp-webapp-prod-0a018824
x-envoy-upstream-service-time: 27
x-pinterest-rid: 3740435078135567
date: Thu, 12 Dec 2019 04:58:50 GMT
set-cookie: _routing_id="4639293c-1b1c-4844-b642-fdcf483d7b2a"; Max-Age=86400; Path=/; HttpOnly
x-cdn: akamai
strict-transport-security: max-age=31536000 ; includeSubDomains ; preload

{"code":"MethodNotAllowed","message":"OPTIONS is not allowed"}
himarshaj commented 4 years ago
hjayanet@E-3102-15:~$ curl -I https://demo.ckan.org/api/3/action/package_search?q=spending&callback=myFunc
[3] 17239
hjayanet@E-3102-15:~$ HTTP/2 200 
date: Wed, 11 Dec 2019 21:03:22 GMT
content-type: application/json;charset=utf-8
content-length: 213
set-cookie: __cfduid=da3935b1074079ec4fdd628a9626d12c91576098202; expires=Fri, 10-Jan-20 21:03:22 GMT; path=/; domain=.ckan.org; HttpOnly; Secure
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 543a67a34f8af102-IAD

Expected MIME type - application/javascript

ibnesayeed commented 4 years ago

@himarshaj you did not quote the URI which contains & in it which is interpreted to run the command in the background. You can either escape unsafe characters or simply quote the URI. By doing so, you will note that it returns correct MIME type (i.e., application/javascript when a JSON-P callback function is specified, application/json otherwise).

$ curl -i "https://demo.ckan.org/api/3/action/package_search?q=spending&callback=myFunc"
HTTP/2 200 
date: Thu, 12 Dec 2019 15:23:42 GMT
content-type: application/javascript;charset=utf-8
content-length: 222
set-cookie: __cfduid=d60e2a9b00ca29c19c789d7730d9e10781576164222; expires=Sat, 11-Jan-20 15:23:42 GMT; path=/; domain=.ckan.org; HttpOnly; Secure
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 5440b3739e3ceaa2-IAD

myFunc({"help": "https://demo.ckan.org/api/3/action/help_show?name=package_search", "success": true, "result": {"count": 0, "sort": "score desc, metadata_modified desc", "facets": {}, "results": [], "search_facets": {}}});
$ curl -i "https://demo.ckan.org/api/3/action/package_search?q=spending"
HTTP/2 200 
date: Thu, 12 Dec 2019 15:24:19 GMT
content-type: application/json;charset=utf-8
content-length: 213
set-cookie: __cfduid=dafd01dd5b86389108fcaff6660eed5b81576164258; expires=Sat, 11-Jan-20 15:24:18 GMT; path=/; domain=.ckan.org; HttpOnly; Secure
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 5440b4583fe256c7-IAD

{"help": "https://demo.ckan.org/api/3/action/help_show?name=package_search", "success": true, "result": {"count": 0, "sort": "score desc, metadata_modified desc", "facets": {}, "results": [], "search_facets": {}}}
himarshaj commented 4 years ago

@ibnesayeed Okay, That explains..