Rooyca / obsidian-api-request

Obsidian plugin that allows you to make requests to API's and receive responses in codeblocks or store them in localStorage.
https://rooyca.github.io/obsidian-api-request/
MIT License
78 stars 4 forks source link

[Feature request] use yaml properties in query #9

Closed tlwt closed 2 months ago

tlwt commented 2 months ago

it would be great if the plugin could support dynamic requests with references to yaml properties

e.g. if in =this.name the value John Doe

Then something like

url: https://app.monicahq.com/api/contacts?query={{this.name}}

would cause a query to

url: https://app.monicahq.com/api/contacts?query=John Doe

Especially with the dynamic templates this would allow inclusion of very detailed information into obsidian.

Rooyca commented 2 months ago

Hey, I like this idea but can you elaborate a little bit more? Where the variables would be define?

tlwt commented 2 months ago

In Obsidian you can define variables within the markdown file.

Just copy & paste the markdown below (or use this file Demo Variables.md) to an obsidian file and if you change to reading view you will the the resolved variables.

---
variable_name: Value of the variable
another_var: TestValue
first_name: Till
---

Just copy & paste this content to obsidian.

`=this.variable_name` 

Best regards, `=this.first_name`
Rooyca commented 2 months ago

Now variables can be also use in the header and body. Although It's a little tricky because a full JSON variables will not work so this should be used only for small things.

For instance:

This would NOT work

---
hea: {"id": 1}
---
url: http://example.com
headers: {{this.hea}}

This WOULD work

---
hea: 1
---
url: http://example.com
headers: {"id": {{this.hea}}}