kasper / phoenix

A lightweight macOS window and app manager scriptable with JavaScript
https://kasper.github.io/phoenix/
Other
4.39k stars 128 forks source link

how can I make a fetch request? #328

Closed yangkennyk closed 1 year ago

yangkennyk commented 1 year ago

This may be a silly question but how can I make a fetch request on events?

I tried using node-fetch, got, axios but it doesn't seem to work and I'm not sure why.

I'm trying to interact with https://www.scriptkit.com/ via a fetch request.

thanks!

kasper commented 1 year ago

@yangkennyk Hi! Phoenix doesn’t provide this in its native API. Node modules won’t work since Phoenix doesn’t run on Node.

What you can do instead is use the Task.run(…) (https://kasper.github.io/phoenix/api/task) API and use for example curl or wget.

kasper commented 1 year ago

I added an example to the documentation.

// Fetch a JSON
Task.run('/usr/bin/curl', ['-s', 'https://api.github.com/repos/kasper/phoenix/releases'], (task) => {
  console.log('Result:', JSON.parse(task.output));
});