somenonymous / OshiUpload

Ephemeral file sharing engine
Do What The F*ck You Want To Public License
164 stars 23 forks source link

Generalize use of the JSON response format #21

Open amotl opened 1 year ago

amotl commented 1 year ago

Dear @somenonymous,

first things first: Thank you so much for conceiving this project, for operating oshi.at, and for its excellent command-line documentation.

We've just used oshi.at, with curl, within one of our example documentations at ^1.

countries_url=$(curl --silent --header 'X-Requested-With: XMLHttpRequest' \
   --form f=@sql/countries.json https://oshi.at | jq -r '.files[0].url')
crash -c "COPY guestbook.countries FROM '${countries_url}' RETURN SUMMARY;"

You will see that we used the --header 'X-Requested-With: XMLHttpRequest' option to make oshi.at respond with JSON format, which we needed in order to find out about the effective download URL using jq -r '.files[0].url. We recognized that you may have implemented it mostly to support the HTML user interface on oshi.at, because it hasn't been documented on the command-line documentation at all.

In this manner, we would like to propose that the JSON response could be generalized and made easier accessible. We have a few suggestions to make the JSON response format available...

a) by honoring the Accept: application/json header, other than the X-Requested-With: XMLHttpRequest header. b) also for PUT requests. Currently, it only seems to work for POST requests. c) via request parameter format=json (POST: curl -F format=json and PUT: https://oshi.at/?format=json). d) by adding the corresponding options (old and new) to the command-line documentation more prominently.

We hope that you will find our suggestions reasonable. Please let us know about your opinion, so that we may submit a patch if you think those improvements would be valuable.

With kind regards, Andreas.

somenonymous commented 1 year ago

Thank you very much for this proposal, it certainly makes sense to be implemented.