Http To Https - Talk to https only APIs

Posted on
  • While creating a subscriber display for my girlfriends YouTube channel with my original Espruino I ran into an issue where the Google YouTube Data API only accepts connections over Https. The original Espruino, and ESP8266 builds, don't support https like the Pico so I created httptohttps.xyz to bridge the Espruino to the Https only service.

    Check out http://httptohttps.xyz/ for how to use it, I tried to make the homepage look nice. You can use the service however you'd like but I can't promise any up-time or reliability guarantees and I ask that you don't use it for commercial purposes.

    Example (This is on an ESP as an Espruino)::

    var http = require("http");
    http.get("http://httptohttps.xyz/https://api.github.com/users/MrTimcakes", function(res) {
      var contents = "";
      res.on('data', function(data) { contents += data; });
      res.on('close', function() { console.log("MrTimcakes is from: " + JSON.parse(contents)["location"]); });
    });
    

    prints "MrTimcakes is from: Great Britain"

    I will gladly take, and even ask for, suggestions to improve the service like Headers n' stuff.
    I will shortly make this open-source too.

  • Wow, that's awesome. Thanks!

    It's quite fun to provide an insecure way to access secure-only things :)

    If only you could register htt.ps you could have http://htt.ps/api.github.com/users/MrTimcakes

  • @Ducky like to use this httptohttps.xyz to access fencer.io

    Fencer is working with data in header and returns json.

    so like to try the bridge with curl to find if a position is in a fence like this:

    curl \
    -H "Authorization: {API Key} " \
    -H "Lat-Pos: {Latitude coordinate} " \
    -H "Lng-Pos: {Longitude coordinate}" \
    http://httptohttps.xyz/https://api.fencer.io/v1.0/position/status/{access key}

    Can the bridge handle something like this ?

    Next step is to use js on espruino ;-)

  • Yeah that works no problem, after I added custom header support ;)

    I̶t̶ ̶s̶h̶o̶u̶l̶d̶ ̶w̶o̶r̶k̶ ̶w̶i̶t̶h̶ ̶h̶t̶t̶p̶.̶r̶e̶q̶u̶e̶s̶t̶ ̶b̶u̶t̶ ̶I̶ ̶c̶a̶n̶'̶t̶ ̶g̶e̶t̶ ̶a̶n̶y̶ ̶f̶o̶r̶m̶ ̶o̶f̶ ̶t̶h̶a̶t̶ ̶t̶o̶ ̶w̶o̶r̶k̶,̶ ̶e̶v̶e̶n̶ ̶i̶f̶ ̶t̶h̶e̶r̶e̶ ̶i̶s̶n̶'̶t̶ ̶a̶n̶y̶ ̶c̶u̶s̶t̶o̶m̶ ̶h̶e̶a̶d̶e̶r̶s̶.̶

    And ready for Espruino here you go:

    var options = {
      host: 'httptohttps.xyz',
      path: '/https://api.fencer.io/v1.0/geofence',
      method: 'GET',
      headers: { "Authorization" : "YOUR-KEY-HERE" }
    };
    require("http").get(options, function(res) {
      var contents="";
      res.on('data', function(data) {
        console.log(data);
      });
      res.on('close', function(data) {
        console.log("Connection closed");
      });
    });
    

    Something strange happens if I try add data to contents though, it just returns false, that's why I thought I couldn't get it to work.

  • Thanks - that was quick ;-)

    This is what a verbose curl call gets when adding valid header data:

    < HTTP/1.1 200 OK
    < Date: Sun, 04 Sep 2016 04:00:02 GMT
    < Server: Apache/2.4.18 (Ubuntu)
    < Content-Length: 123
    < Vary: Accept-Encoding
    < Content-Type: text/html; charset=UTF-8
    < 
    * Connection #0 to host httptohttps.xyz left intact
    {
    "data": {
            "inside":false,
            "enter":{
                 "Distance":0.046,
                 "Bearing":336.5
            },
            "origin":{
                "Distance":0.049,
                "Bearing":328
            }},
            "error":null
    }
    
  • ok - took the sample code, added keys and headers - works fine - thanks again.

  • Hi @Ducky

    this link points to a sample Espruino module named FencerIO.js to call fencer.io using your bridge

  • @patreon is this site still available? Can others use it?

  • I believe it's @MrTimcakes that develops it.

    While that link is dead it looks from http://forum.espruino.com/conversations/305047/?offset=25 like it's alive at HttpToHttps.MrTimcakes.com

  • Looks like it's still on the domain, but on "www" rather than the apex -> http://www.httptohttps.xyz/

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Http To Https - Talk to https only APIs

Posted by Avatar for MrTimcakes @MrTimcakes

Actions