Rooyca / obsidian-api-request

Obsidian plugin that allows you to make HTTP requests and display responses directly in the document, in codeblocks, or store them in localStorage.
https://rooyca.github.io/obsidian-api-request/
MIT License
100 stars 5 forks source link

Allow for {{this.file.name}} and other functions to be used when using "show" #27

Closed elvarb closed 3 months ago

elvarb commented 3 months ago

Describe the bug I'm querying the Shodan API to resolve domain names into IP

Shodan API Documentation -> https://developer.shodan.io/api

With this api you can query for multiple dns names at once but I just want to query for one using the {{this.file.name}} function

url: https://api.shodan.io/dns/resolve?hostnames={{this.file.name}}&key=
response-type: json

The results Shodan returns is for example

{
    "google.com": "172.217.6.46",
    "facebook.com": "157.240.22.35"
}

Using the following just returns "undefined"

url: https://api.shodan.io/dns/resolve?hostnames={{this.file.name}}&key=
response-type: json
show: {{this.file.name}}

Expected behavior

Using the query above it should result in "172.217.6.46"

Rooyca commented 3 months ago

I was thinking on this the other day but never came to implement it. Is really easy, it should be live in the next update.

P.S. The response-type flag is not longer used. Response will be render automatically using the header Content-Type.

I keep changing and removing things (sorry about that). You can always read the docs for the latest changes https://rooyca.github.io/obsidian-api-request/en/codeblocks/

elvarb commented 3 months ago

Not a problem, this plugin has such a great potential that all changes should be good.

I think that the response-type should be re implemented as an optional fallback feature when the server does not return a correct content-type or some content type that is not standard. For example I was just testing another api where the content type for it is "application/rdap+json; charset=UTF-8" and the plugin does not see it as a valid json even though it is.

Rooyca commented 3 months ago

re implemented as an optional fallback feature

You're right. I'll re implement it but shorter: res-type.

Thanks again for all the feedback.