Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: Create a RESTFUL Server

  1. #1
    Join Date
    May 2004
    Location
    France
    Posts
    250

    Question Create a RESTFUL Server

    Hello,

    I want to create a RestFul server within G6 with lua to be able to be compliant with the new "ImperiHome Standard System API".

    What is the simplest way to create such a TCP server in G6 ?
    Is there any sample to start with ?

    Thanks

  2. #2
    Join Date
    May 2004
    Location
    France
    Posts
    250

    Question

    Hello,

    Nobody to answer ?

    If this kind of code the good starting ?

    Code:
    local socket = require 'socket'
    local server = socket.tcp()
    server:bind('*',51423)
    server:listen(32)
    local client = server:accept()
    But I don't know how to use the client object next ...

    And when I run the code above, it freezes my Girder 6...

  3. #3
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    You should probably do that on a Lua Thread...
    Ron
    No support through PM

  4. #4
    Join Date
    May 2004
    Location
    France
    Posts
    250

    Question

    Sorry, I'm not very friend with LUA.

    Where to add the thread.newthread ?

    Code:
    local socket = require 'socket'
    local server = socket.tcp()
    server:bind('*',51423)
    server:listen(32)
    local client = server:accept()  
    while 1 do
      -- wait for a connection from any client
      local client = server:accept()
      -- make sure we don't block waiting for this client's line
      client:settimeout(10)
      -- receive the line
      local line, err = client:receive()
      -- if there was no error, send it back to the client
      if not err then 
        print ("DEBUG : " .. line)
        client:send(line .. "\n") 
      end
      -- done with client, close the object
      client:close()
    end
    Thanks

  5. #5
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    Maybe we should take a different approach. If you are not familiar with threads this could end badly

    Girder already has a built-in webserver. This webserver is scriptable. Combine those two and you can quickly build a restfull server.

    For example look at <GIRDERINSTALL>\httpd\gir\triggerEvent.lhtml
    Ron
    No support through PM

  6. #6
    Join Date
    May 2004
    Location
    France
    Posts
    250

    Default

    I come back on this thread.

    My Restfull web server must answer to a query like http://girderserver/iss/system

    I created an index.lhtml page in <GIRDERINSTALL>\httpd\iss\system

    If I query from a browser, I get my answer. it's seems OK.
    But if I query from the device suppose to query the restfull service, it failed.
    In fact, it probably doesnt like the HTTP 301 redirect (to index.lhtml)

    How to avoid that ?

    I do the same tests from an apache/php server

    apache log query from device
    Code:
    192.168.1.XXX - - [26/Aug/2014:22:39:31 +0200] "GET /iss/system HTTP/1.1" 301 240 "-" "-"
    apache log query from browser
    Code:
    192.168.1.YYY - - [26/Aug/2014:22:59:43 +0200] "GET /iss/system/ HTTP/1.1" 200 30 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"





    Last edited by rgouyet; August 27th, 2014 at 07:45 AM.

  7. #7
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    looks like /iss/system is a directory. So the 301 response is not a surprise at all. Note that your browser is in fact querying a different url /iss/system/

    Most likely the /iss/system is being forwarded to /iss/system/ using that 301.
    Ron
    No support through PM

  8. #8
    Join Date
    May 2004
    Location
    France
    Posts
    250

    Default

    I understood that...
    So the only way seems to be to create a tcp listener to make the restfull server.

    I found many sample in PHP but nothing in LUA ...

  9. #9
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    I'm confused. Are you trying to make Girder be the server or apache?
    Ron
    No support through PM

  10. #10
    Join Date
    May 2004
    Location
    France
    Posts
    250

    Default

    Girder must be the server to be able to serve the imperihome android application

    The spec of the RESTFULL server to implement in Girder are describe here.
    There are 5 url to serve :

    GET /devices
    List all devices and scenes
    GET /devices/{deviceId}/action/{actionName}/{actionParam}
    Perform the specified device action
    GET /devices/{deviceId}/{paramKey}/histo/{startdate}/{enddate}
    ​Get device's parameter historical values
    GET /rooms
    List all rooms
    GET /system
    Get system informations

    I just need an help to be able to answer the above HTTP queries from Girder

Page 1 of 3 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •