This post is about CommonJS Package, a library, allowing consumers to list, read, write, delete & comment private / public gists. Library employs v2 & v1 Github API’s in combination with some dirty hacks to make this possible.
Main target platform is a browser, but it can run on any other platform that will provide implementation of XMLHttpRequests. Since browsers have many limitations in comparison to other platforms this idea was a challenge form a beginning. The first thing and probably something you already have in mind is same origin policy. Luckily all modern browsers today implement W3C standard for cross-origin resource sharing. Unfortunately though, only a few websites employ this technique and reply client with
Access-Control-Allow-Origin headers. Believe me or not, Github is not one of those!! Actually convincing them to start useing this standard was not as easy either…
I did not want to give up, so I have decide to implement this library anyway with accompany of two proof of concept experiments demoed in previous posts. I really hope this way I’ll get enough attention from Github folks and they will see a value of improved browser friendly Gist API’s :)
Access-Control-Allow-Origin headers, same origin policy problem was solved, as a side effect it also allowed some optimizations by moving several operations from client to server.
Unfortunately it’s not the end of the story neither it was end of the issues I had to run into. After a while I discovered that firefox sends
HTTP OPTONS request, before sending desired
HTTP POST on which replies without necessary
Access-Control-Allow-Origin header. With
HTTP GET everything is fine since
HTTP OPTIONS are not send in that case. Other browsers don’t have issues nor with
GET nor with
POST since they don’t seem to send
HTTP OPTIONS. I have reported about this issue to folks and they were super fast with picking it up, they plan to have a fix in for a next release, which I hope will be anytime soon.
After all the efforts github library is ready to be forked!! So please give it a try and lets make some amazing stuff to show Github folks that, ###we need a better Gist API’s!!###