Loading ...
Sorry, an error occurred while loading the content.

Announcing web_send: a browser shell for JSON resources

Expand Messages
  • Tyler Close
    The web_send library provides a concise and expressive API for interacting with arbitrary JSON resources from the web browser. When used from the Firebug
    Message 1 of 3 , May 7, 2009
    • 0 Attachment
      The web_send library provides a concise and expressive API for
      interacting with arbitrary JSON resources from the web browser. When
      used from the Firebug console, it acts like a command line for your
      web server; a great help during development of server-side code. The
      same API is also convenient for creating an AJAX user interface to
      JSON resources; so code born on the interactive command line migrates
      smoothly into application code. This tutorial also links to a live web
      page <http://waterken.sourceforge.net/bang/> where you can try out the
      library against a simple server-side counter object.

      SOME QUICK INTRODUCTORY EXAMPLES

      For example, say you've got a brand new server-side object sitting at
      a URL like: <https://example.com/myApp/obj123>. All you want to do is
      invoke one of its methods, to see what happens. Using the web_send
      library from the Firebug console, you could write:

      factory = lib.web.getLocation(); // grab the window.location URL
      drum = lib.Q.post(factory, 'makeDrum', []);

      That code generates the following HTTP request:

      POST /myApp/obj123?q=makeDrum HTTP/1.1
      Host: example.com
      Content-Type: text/plain; charset=UTF-8
      Content-Length: 2

      []

      The arguments to Q.post() are:

      1. remote reference for the target object
      2. optional argument to add to the query string
      3. optional JSON value for the request body

      The makeDrum() method didn't take any arguments. Here's one that does:

      lib.Q.post(drum, 'bang', [ 1 ]);

      Causing the HTTP request:

      POST /myApp/obj456?q=bang HTTP/1.1
      Host: example.com
      Content-Type: text/plain; charset=UTF-8
      Content-Length: 5

      [ 1 ]

      The target URL in the above request was taken from the HTTP response
      to the previous request. For this to work, the web_send library
      introduces some conventions for HTTP requests and responses. These
      conventions are the least restrictive they can be, while still
      supporting the client-side remote reference API. This document
      explains these conventions and shows how to use legacy JSON resources
      that don't follow the conventions.

      ... (continue reading at <http://waterken.sourceforge.net/web_send/>)

      --
      "Waterken News: Capability security on the Web"
      http://waterken.sourceforge.net/recent.html
    • Kris Zyp
      This looks really cool. Have you tried it with existing servers to see how compatible it is with current implementations of HTTP/JSON servers? This data
      Message 2 of 3 , May 7, 2009
      • 0 Attachment
        This looks really cool. Have you tried it with existing servers to see
        how compatible it is with current implementations of HTTP/JSON servers?
        This data interaction aspect of this looks similar to the functionality
        in Dojo's JsonRestStore, which can interact with CouchDB and Persevere.
        It'd be curious if your browser shell works with Persevere, as Persevere
        follows RFC 2616 pretty closely as well as some of the RESTful JSON
        conventions discussed here, such as JSON referencing:
        http://groups.google.com/group/restful-json
        Kris

        Tyler Close wrote:
        >
        >
        > The web_send library provides a concise and expressive API for
        > interacting with arbitrary JSON resources from the web browser. When
        > used from the Firebug console, it acts like a command line for your
        > web server; a great help during development of server-side code. The
        > same API is also convenient for creating an AJAX user interface to
        > JSON resources; so code born on the interactive command line migrates
        > smoothly into application code. This tutorial also links to a live web
        > page <http://waterken.sourceforge.net/bang/
        > <http://waterken.sourceforge.net/bang/>> where you can try out the
        > library against a simple server-side counter object.
        >
        > SOME QUICK INTRODUCTORY EXAMPLES
        >
        > For example, say you've got a brand new server-side object sitting at
        > a URL like: <https://example.com/myApp/obj123
        > <https://example.com/myApp/obj123>>. All you want to do is
        > invoke one of its methods, to see what happens. Using the web_send
        > library from the Firebug console, you could write:
        >
        > factory = lib.web.getLocation(); // grab the window.location URL
        > drum = lib.Q.post(factory, 'makeDrum', []);
        >
        > That code generates the following HTTP request:
        >
        > POST /myApp/obj123?q=makeDrum HTTP/1.1
        > Host: example.com
        > Content-Type: text/plain; charset=UTF-8
        > Content-Length: 2
        >
        > []
        >
        > The arguments to Q.post() are:
        >
        > 1. remote reference for the target object
        > 2. optional argument to add to the query string
        > 3. optional JSON value for the request body
        >
        > The makeDrum() method didn't take any arguments. Here's one that does:
        >
        > lib.Q.post(drum, 'bang', [ 1 ]);
        >
        > Causing the HTTP request:
        >
        > POST /myApp/obj456?q=bang HTTP/1.1
        > Host: example.com
        > Content-Type: text/plain; charset=UTF-8
        > Content-Length: 5
        >
        > [ 1 ]
        >
        > The target URL in the above request was taken from the HTTP response
        > to the previous request. For this to work, the web_send library
        > introduces some conventions for HTTP requests and responses. These
        > conventions are the least restrictive they can be, while still
        > supporting the client-side remote reference API. This document
        > explains these conventions and shows how to use legacy JSON resources
        > that don't follow the conventions.
        >
        > ... (continue reading at <http://waterken.sourceforge.net/web_send/
        > <http://waterken.sourceforge.net/web_send/>>)
        >
        > --
        > "Waterken News: Capability security on the Web"
        > http://waterken.sourceforge.net/recent.html
        > <http://waterken.sourceforge.net/recent.html>
        >
        >
      • Tyler Close
        ... Thanks! ... The implementation currently supports GET and POST to an arbitrary URL with an arbitrary JSON request entity and an arbitrary JSON response
        Message 3 of 3 , May 7, 2009
        • 0 Attachment
          On Thu, May 7, 2009 at 10:51 AM, Kris Zyp <kriszyp@...> wrote:
          > This looks really cool.

          Thanks!

          > Have you tried it with existing servers to see
          > how compatible it is with current implementations of HTTP/JSON servers?
          > This data interaction aspect of this looks similar to the functionality
          > in Dojo's JsonRestStore, which can interact with CouchDB and Persevere.
          > It'd be curious if your browser shell works with Persevere, as Persevere
          > follows RFC 2616 pretty closely as well as some of the RESTful JSON
          > conventions discussed here, such as JSON referencing:
          > http://groups.google.com/group/restful-json

          The implementation currently supports GET and POST to an arbitrary URL
          with an arbitrary JSON request entity and an arbitrary JSON response
          entity. Non-success HTTP response codes trigger the provided failure
          callback.

          Is there some aspect of Persevere's implementation of RFC 2616 that
          could be problematic for a client implemented on the browser's
          XMLHttpRequest object?

          All JSON encoding/decoding is done using whatever JSON object is in
          the global scope. It looks like you could use your JSON referencing
          code by importing it instead of json2.js.

          --Tyler

          --
          "Waterken News: Capability security on the Web"
          http://waterken.sourceforge.net/recent.html
        Your message has been successfully submitted and would be delivered to recipients shortly.