
Show HN: Invoking web APIs as if they were JavaScript methods - fmontesi
https://github.com/fmontesi/jo
======
lozzo
Could you put an example of a real web API (maybe the github API) and show how
you would call it with your library ?

~~~
fmontesi
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](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 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.

~~~
fmontesi
By the way, here's the Telegraph API documentation, for reference:
[https://telegra.ph/api](https://telegra.ph/api)

What I wrote in my reply refers to that.

~~~
lozzo
ok, makes more sense now. well done.

------
fmontesi
A small library I made for fun. It's very early stage and I wanted to keep
things simple, so it does not use any other established libraries (yet).

------
carbonem
Really cool, I’m impressed!

