callback parameter for json search API

MirceaKitsune

Greetings! I hope here is the correct place to write about my issue, as I understand this is where I should post regarding site functionality concerns.
 
I wish to request a very minor change to the json API of the site, if you could please consider implementing this adjustment. I’m developing a plugin that works with multiple art sites, and I’ve wanted to add Derpibooru as a supported source as well. However due to this limitation, I cannot currently integrate it with my system.
 
https://derpibooru.org/pages/api
 
I’m looking at the API that’s used to search for submissions and return an object containing the results. For example: If I wish to search for the keyword “dragon” I use this URL to get an output of the following form:
 
https://derpibooru.org/search.json?q=dragon
 
{foo, bar}
 
The feature I’m requesting is the callback parameter, which is supported by identical API’s on other websites. Its function is simple: It wraps the returned string inside function tags, which allow the received data to be executed directly. To use my above example, I would call the URL in the following way and get this result instead:
 
https://derpibooru.org/search.json?q=dragon&callback=my_function
 
my_function({foo, bar})
 
You can see the difference in action on sites that offer this parameter, such as e621:
 
https://e621.net/post/index.json?tags=dragon&limit=10  
https://e621.net/post/index.json?tags=dragon&limit=10&callback=my_function
 
Currently adding &callback=whatever does nothing on Derpibooru. Since what I’m doing uses JavaScript on an HTML page, the only working option I found is to embed this URL as a script source. On sites that offer the callback parameter, this already works flawlessly! Could you please consider making this minor adjustment on Derpibooru as well? Thank you very much.
MirceaKitsune

@Luna
 
I tried working with XMLHttpRequest, however it doesn’t really work with my approach. The main issue was the cross-origin policy thing, which says you can’t access content from another domain in your scripts… I looked up several threads and tried for hours but couldn’t get around that in the end.
 
The only thing that did work flawlessly was to use this callback parameter, by creating a script and attaching the url as its src. That way when the script loads, it automatically calls my function of choice with the data it receives, which is very clean and efficient.
MirceaKitsune

@MirceaKitsune
we will not support JSONP, ever.
 
I had to look that term up again, and JSONP seems to be what I’m referring to. It’s sad to hear you don’t plan on supporting it, considering it seems very basic and I can’t think of how it could be harmful either. But at least I know this is a decision of the team and not a missing feature. Thanks for clarifying.
byte[]
Solar Supporter - Fought against the New Lunar Republic rebellion on the side of the Solar Deity (April Fools 2023).
Non-Fungible Trixie -
Verified Pegasus - Show us your gorgeous wings!
Preenhub - We all know what you were up to this evening~
An Artist Who Rocks - 100+ images under their artist tag
Artist -

Philomena Contributor
@MirceaKitsune  
The reason we aren’t using JSONP has to do with plugging cross-origin request security holes. We run the tightest ship we can manage when it comes to end user security.
 
There may be other ways of obtaining the information you need, but we are not going to modify CORS or implement JSONP for API client benefit.
MirceaKitsune

@MirceaKitsune
The reason we aren’t using JSONP has to do with plugging cross-origin request security holes. We run the tightest ship we can manage when it comes to end user security.
There may be other ways of obtaining the information you need, but we are not going to modify CORS or implement JSONP for API client benefit.
 
I understand. I might have one last hope in that case: I remember reading of an alternative way to get such data in JS, but I’m not sure if it involves the same cross-origin policy concerns. It suggested setting the URL as the source of an iframe from which you can then read the json content. When I tried this on some sites however, they said the site doesn’t allow embedding to an iframe, which I understand is possible for websites to disable on demand.
 
Would Derpibooru let me attempt this approach, or is embedding also disallowed? Do you believe at least iframe embedding for the API result can be allowed safely?
Interested in advertising on Derpibooru? Click here for information!
My Little Ties crafts shop

Help fund the $15 daily operational cost of Derpibooru - support us financially!

Syntax quick reference: **bold** *italic* ||hide text|| `code` __underline__ ~~strike~~ ^sup^ %sub%

Detailed syntax guide