Obsidian plugin that allows you to make requests to API's and receive responses in code-blocks or store them in localStorage
.
Important
JSON, TEXT, HTML and MARKDOWN responses supported
The plugin can be installed from within Obsidian.
- Go to
Settings
->Community plugins
- Make sure
Restricted mode
is off - Click
Browse
- Search for
APIRequest
- Click
Install
and thenEnable
There are two ways to use the plugin:
To use it, create a code-block with the language set to req
. Inside the code-block, you can specify url
, method
, body
, headers
, format
, etc.
url: https://api.chess.com/pub/player/hikaru/stats
show: chess_daily -> last -> rating
Multiple outputs can be displayed:
url: https://api.chess.com/pub/player/hikaru/stats
show: chess_daily -> last -> rating, chess_daily -> best -> rating
format: <p>Last game: {}</p> <strong>Best game: {}</strong>
It's possible to loop over an array.
url: https://jsonplaceholder.typicode.com/users
show: {..} -> address -> city
Here is a more complex example:
url: https://my-json-server.typicode.com/typicode/demo/comments
format: <h1>{}</h1>
method: post
body: {"id":1}
headers: {"Accept": "application/json"}
show: id
Responses can be stored in localStorage
with the req-id
flag.
url: https://jsonplaceholder.typicode.com/users/1
show: id
req-id: id-persona
For this you'll need dataview.
dv.paragraph(localStorage.getItem("req-id-persona"))
Is mandatory to use req-
before whatever you defined in req-id
flag.
You could also used inline:
$=localStorage.getItem("req-id-persona")
But this is a little buggy and don't work all the time. (Use this for short and unformatted responses)
In order to remove a response from the localStorage
you can use the following code:
localStorage.removeItem("req-id-persona")
For removing all responses use:
localStorage.clear()
Or just go to the plugin settings and click the button Clear ID's
to remove all responses.
To use the plugin, press Ctrl+P
and search for APIR
. There are two options:
- Show response in modal
- Paste response in current document (at current line)
The plugin has a few settings that you can configure:
- URL: The URL to send the request to.
- Format Output: Just JSON blocks (for now).
- Method: Choose between GET, POST, PUT & DELETE.
- Body: The data to send with the request. Data should by in JSON format.
- Headers: The header data to send with the request. Data should by in JSON format. (
{"Content-Type": "application/json", "Authorization": "Bearer TOKEN"}
) - Response: The response data to display. If empty all data will be display. You can use a right arrow
->
to access nested objects. For example, if you want to show thetitle
from theuser
object, you can do that like this:user -> title
.
- Add more request types (POST, PUT, DELETE)
- Add support for authentication
- Add customization for modal output
If you encounter any issues or have feedback on the plugin, feel free to open an issue on the GitHub repository. Contributions are also welcome!