This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.
Closed

Homey HTTP support

I am proposing to add simple HTTP handling to Homey core.

I've built simple wrapper around node's http https://github.com/matjaz/homey-youtube/blob/master/lib/http.js
It uses promises which are already supported in node 0.12.9.
It supports all common HTTP methods.

Usage is as follows:
var http = require('./http')

http.get('http://httpbin.org/get')
  .then(function (result) {
    console.log('Status code: ' + result.response.statusCode) // raw ServerResponse object
    console.log(result.data) // response contents
  })
  .catch(function (err) {
    console.error(err)
  })

// POST
http.post('http://httpbin.org/post', {test: 'hello'})
  .then(function (result) {
    console.log(result.data)
  })
  .catch(function (err) {
    console.error(err)
  })

// built-in JSON parsing
http.json('http://httpbin.org/get')
  .then(function (data) {
    console.log(data.url) // parsed JSON object
  })
  .catch(function (err) {
    console.error(err)
  })
Comments welcome.

Comments

  • This would be awesome! I love the promise-framework. I use it as well in my Kodi-app.
    +10 for built in HTTP and JSON support!
  • EmileEmile Administrator, Athom
    That's a very nice snippet. However, I'd rather don't 'spoil' core with functionalities that can be achieved natively. For every case there's a best solution.
  • Does Homey 'share' dependent libraries? It would be a shame if a, let's say, JSON library gets installed 5 times because 5 apps happen to use it.
  • EvertorN said:
    Does Homey 'share' dependent libraries? It would be a shame if a, let's say, JSON library gets installed 5 times because 5 apps happen to use it.
    I hope not. That would be he'll for developers. Now I know my app is stable with the libraries and versions I selected. 


  • Uranday said:
    EvertorN said:
    Does Homey 'share' dependent libraries? It would be a shame if a, let's say, JSON library gets installed 5 times because 5 apps happen to use it.
    I hope not. That would be he'll for developers. Now I know my app is stable with the libraries and versions I selected. 


    I hope it does. It shouldn't be a problem since you can define version numbers of dependent libraries in your app.json.
  • IMO, HTTP support is so widespread it should be part of core.

    AFAIK, all npm modules must be added directly to the app before publishing app. So each app has it's own copy of dependencies. App dependencies in app.json are not (yet?) used AFAIK.

    What I suggest is add support directly calling methods of other apps (similar to api), but without http bridge.
    For example
    Homey.getApp('util.http', '~1.0.0').get('http://athom.com').then(...)

    Other use case would be to Chromecast app to use YouTube app search functionality.
    if Homey.appInstalled('com.youtube', '~1.0.0')
    Homey.getApp('com.youtube', '~1.0.0').search('hello world').then(...)

    We need versioning, since apps can became incompatible with new versions. See http://semver.npmjs.com

  • Then you also need to show dependent apps on the app store. Doesn't this complicate the whole app store simplicity?

    What is the benefit of sharing these dependencies? Space?
  • Yeah, You're right. This is just a plain dependency where npm is the best tool to do it's job.

    @Emile I suggest to look into adding support for npm install and optimise dependency handling between apps.

    More interesting is apps that depends on other apps functionality.
  • I've released a simple http.min npm library. In many cases it can replace heavy 'request' package.
  • MatjaLipu said:
    I've released a simple http.min npm library. In many cases it can replace heavy 'request' package.
    Thanks, I'll look into this for the HTTP actions app.
This discussion has been closed.