I am trying to build an Omnigraffle plugin that will need to send and fetch data from our server. So far, I have managed to get the GET API calls to work using URL.fromString (mentioned on this page) as shown below:
var aURL = URL.fromString('https://reqres.in/api/users?page=2');
aURL.fetch(function(data){
console.log(data.toString());
});
Even stackoverflow did not have any helpful information for me. @staff please advise if this is even feasible at all.
As I understand it, this feature is intended to import web hosted assets into a document. I don’t believe it will work as a way to export data. I will look into the boundaries more today to confirm.
Thanks for your response. But, I don’t think that workaround will serve my purpose. I need to make GET/POST/UPDATE/DELETE requests to my web services to send and receive data (JSON mostly). The example you shared can, at best, be used for make GET requests.
Can you let me know if that is even possible? If yes, can you share an example of a POST request being made from the plugin to a web service?
Again, thank you for all your help. Appreciate it.
The fetch() method of the URL class can be used to retrieve data from some web services, as in this example of getting today’s weather for Cupertino, California from NOAA:
var aURL = URL.fromString('https://graphical.weather.gov/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?zipCodeList=95014&format=24+hourly&numDays=1');
aURL.fetch(function(data){
console.log(data.toString());
});
Unless something’s changed in the last year or so, only GET seems to be exposed. I can imagine there were security concerns behind that decision, but I think (and still hold hope) that there will be full HTTP method support at some stage.
What I was trying to do last year has been put on hold because I need to POST in addition I GET.
Thanks for your effort. I really appreciate it. But, suppose I have to call a login service to which I need to send my username and password as POST parameters. How can I accomplish that using the URL class?
Here’s an example of a fetch POST request from the MDN JavaScript documentation:
var url = 'https://example.com/profile';
var data = {username: 'example'};
fetch(url, {
method: 'POST', // or 'PUT'
body: JSON.stringify(data), // data can be `string` or {object}!
headers:{
'Content-Type': 'application/json'
}
}).then(res => res.json())
.catch(error => console.error('Error:', error))
.then(response => console.log('Success:', response));
Can you share the Omnigraffle plugin equivalent of this code?
I’ve confirmed with engineering that at this time, the fetch( ) method of the URL class only supports retrieving data (GET) and not the ability to include header data (POST). Thanks to all for their comments and examples. – SAL
Thank you for looking into this Sal. If anyone else sees this thread and needs a way to POST, please email us a request at omnigraffle@omnigroup.com so that we can make sure your suggestion is tracked.