deeplook / ipyrest

An emerging widget for exploring RESTful APIs in Jupyter notebooks.
MIT License
28 stars 4 forks source link

Find and use file extension in URL in addition to MIME types #9

Open deeplook opened 5 years ago

deeplook commented 5 years ago

Given that many sites do not provide proper MIME types for some content, like GitHub gists, it would be useful to try extracting a "file extension" from the URL and derive a MIME type and ipyrest response view. Either using the builtin mimetypes and/or some additional mapping. Then it would be less necessary to use a separate step for post-processing the response before rendering it.

jtpio commented 5 years ago

The mimetypes module from the standard library could be worth a try:

import mimetypes
mimetypes.guess_type('https://raw.githubusercontent.com/jupyterlab/jupyterlab-demo/master/data/iris.csv')
('text/csv', None)

Not sure how well it would handle more exotic MIME types though.