Show HN: Invoking web APIs as if they were JavaScript methods
1–8 of 8 posts
Re: Show HN: Invoking web APIs as if they were JavaScript methods
#2Re: Show HN: Invoking web APIs as if they were JavaScript methods
#3Re: Show HN: Invoking web APIs as if they were JavaScript methods
#4Re: Show HN: Invoking web APIs as if they were JavaScript methods
#5Could you put an example of a real web API (maybe the github API) and show how you would call it with your library ?
To create an account:
Jo.createAccount( { shortName: "Homer" } ) .then( response => { alert( response.result.accessToken ); } );
To create a page:
Jo.createPage( { accessToken: token, title: "Title", content: "Content" } ) .then( response => { alert( response.result.url ); } );
This assume that those operations are available at the originating web server. If instead you're offering "Telegraph" as a subservice, then instead of Jo you have to write Jo("Telegraph"), the rest is the same.
I hope this clarifies things a bit.
Re: Show HN: Invoking web APIs as if they were JavaScript methods
#6Could you put an example of a real web API (maybe the github API) and show how you would call it with your library ?
I can give you one by reusing a bit the Telegraph example I have in the Jo tutorial: http://fmontesi.github.io/2018/08/16/jo.html To create an account: Jo.createAccount( { shortName: "Homer" } ) .then( response => { alert( response.result.accessToken ); } ); To create a page: Jo.createPage( { accessToken: token, title: "Title", content: "Content" } ) .then( response => { alert( response.result.url ); } ); This assume…
What I wrote in my reply refers to that.
Re: Show HN: Invoking web APIs as if they were JavaScript methods
#7Could you put an example of a real web API (maybe the github API) and show how you would call it with your library ?
I can give you one by reusing a bit the Telegraph example I have in the Jo tutorial: http://fmontesi.github.io/2018/08/16/jo.html To create an account: Jo.createAccount( { shortName: "Homer" } ) .then( response => { alert( response.result.accessToken ); } ); To create a page: Jo.createPage( { accessToken: token, title: "Title", content: "Content" } ) .then( response => { alert( response.result.url ); } ); This assume…
Jor["users/fmontesi/repos"].get().then( response => ... );
Notice that using ["users/fmontesi/repos"] is the "alternative" syntax. If the resource path is a valid method name in JavaScript, e.g., "/users", you can just write this:
Jor.users.get().then( response => ... );
I'm still wondering what's the best way of offering resource paths. Using a string is fine, but another option would be to have an extension of JavaScript, like JSX in react, but that would add a dependency (on Babel, for example). So we could do something like:
Jor.users/fmontesi/repos.get().then( response => ... );
Another option could be to use an in-between method, for example:
Jor.users._.fmontesi._.repos.get().then( response => ... );
But this looks a bit clunky. So the design space is a bit larger here. Mumble mumble. :-)
Re: Show HN: Invoking web APIs as if they were JavaScript methods
#8Earlier quoted context omitted.
I can give you one by reusing a bit the Telegraph example I have in the Jo tutorial: http://fmontesi.github.io/2018/08/16/jo.html To create an account: Jo.createAccount( { shortName: "Homer" } ) .then( response => { alert( response.result.accessToken ); } ); To create a page: Jo.createPage( { accessToken: token, title: "Title", content: "Content" } ) .then( response => { alert( response.result.url ); } ); This assume…
By the way, here's the Telegraph API documentation, for reference: https://telegra.ph/api What I wrote in my reply refers to that.