Shop OBEX P1 Docs P2 Docs Learn Events
RESTful services vs HTML — Parallax Forums

RESTful services vs HTML

WildatheartWildatheart Posts: 195
edited 2013-02-22 05:47 in Accessories
Mike, in another thread you wrote, "I originally designed the Spinneret libraries for RESTful services. However, the community for some reason latched onto HTML. I guess I need to build another example."

In the couple of project examples I posted recently, I was happy to receive 4 bits of data via the Spinneret/internet using my cell phone to drive some hardware. Although my current programming ability limits me to one way communication with the Spinneret, I hope to experiment with using the return value "xmlstr" (if I referred to the variable correctly from your epin.htm).

This will tell you that (at this time) I'm either POSTing and not GETing, or I'm GETing and not POSTing. I again reviewed your tutorial, and I looked at a couple of additional explanations. For sure, I'm not GETing 'it'! (No pun intended.)

What exactly do the Spinneret libraries for RESTful services do that HTML doesn't do? Does it expand capability to send and receive files, strings, etc.?

Your epin.htm has been an excellent! source of learning for me. If my use of epin has been limited to HTML, could you please provide something similar to take advantage of RESTful services.

Comments

  • Mike GMike G Posts: 2,702
    edited 2013-02-20 19:17
    If my use of epin has been limited to HTML, could you please provide something similar to take advantage of RESTful services.
    epin.htm is an example of a RESTful client request. The Spin code running on the web server retrieves the client request and returns an beautiful XML document that can be consumed on any platform. The epin.htm demo uses a browser to perform the task because everyone has a browser - easy peasy.

    Now we're seeing the Spinneret code evolve and folks are starting to ask, How do I get the values into a application. Well, the answer is right in front of you... only you can't see the XML through the HTML.
  • WildatheartWildatheart Posts: 195
    edited 2013-02-20 20:05
    Okay. So... if I'm using a browser, and if I'm using epin, then I should frame and place pinvalue or epinvalue in a place where my VB8 application has access to it? Is that the XML I should see?
  • Mike GMike G Posts: 2,702
    edited 2013-02-20 20:36
    Okay. So... if I'm using a browser, and if I'm using epin, then I should frame and place pinvalue or epinvalue in a place where my VB8 application has access to it? Is that the XML I should see?
    epin.htm is a self contained client application that runs is a browser. The service is p_encode.xml. The parameter for the service is ?value=-1.


    All togther...
    http://192.168.1.110/p_encode.xml?value=-1
    

    You can type the url (use you Spinneret IP) and see the XML response in a browser. The service URL is what you want in the VB app not the web page.
    http://forums.parallax.com/showthread.php/146147-Sending-bytes-from-Spinneret-to-Visual-Basic?p=1165347&viewfull=1#post1165347

    You're not seeing the XML through the HTML.

    You could request the web page with VB but that would be a pain in the butt to parse.
  • WildatheartWildatheart Posts: 195
    edited 2013-02-21 20:50
    Mike, thank you for taking the time to write HttpClientDemo VB. I downloaded it and found it to be another of your very understandable learning resources. I have a little experience with VB so it made sense to me. Until now (if this is the XML), I alluded to it in lay terms when I mentioned “closed loop” operation as it pertained to validating the set-position of my webcam. I think the BS2 that drives the webcam could request the XML as well.

    So, if I now see the XML through the HTML, I have only one other question that will hopefully be answered after I review the code Doggiedoc is using for his chicken coup – that being, the transfer of byte and string data via XML. Thanks again for your very clear examples.
  • Mike GMike G Posts: 2,702
    edited 2013-02-22 05:47
    So, if I now see the XML through the HTML, I have only one other question that will hopefully be answered after I review the code Doggiedoc is using for his chicken coup – that being, the transfer of byte and string data via XML. Thanks again for your very clear examples.
    Doggiedoc used the same concept as the epin.htm example only his pallet is HTML. Doggiedoc, IIRC, created a web page that contains a div with an ID inside the main HTML page. Inside the div he place an HTML table of sensor values. Doggiedoc also wrote spin code to dynamical generate the div containing the table of values.

    When the main page is loaded, the entire HTLM page is rendered, div, table and all. The main page contains a timer which retrieves the dynamically generated div containing the table of values every X. The dynamically generated HTML replaces the current div element. This was done using JQuery which is a very powerful JavaScript library.

    When you say "transfer of byte and string data via XML" I think you're asking how to cast the data into types. I believe the key here is understanding the current protocol we're using which is HTTP. HTTP is a text base protocol. All the data is represented as ASCII characters.

    If you're goal is to send different data types to the client, XML over HTTP is a good way to go. The elements wrap the data which makes the whole thing somewhat self defining. However, you still need to convert ASCII numeric encoded values to their numeric equivalent for calculation purposes. If your goal is to send actual numeric values not ASCII, that's very doable. The downside is you'll have to create a protocol. You'll need to know where the data elements start and stop, which elements are strings, which are numeric, value length, etc. That involves rolling your own server application. Simply take a look at the DNS or DHCP object for pointers.

    Doggiedoc, converted the numeric sensor values to ASCII before rendering the sensor values. He's not doing any calculation on the values - just display - so no need to convert ASCII to integer.
Sign In or Register to comment.