UED - URL Encoded Data

Written by on March 15th, 2007 in Ajax News.

UED is a tiny library that takes a hash and converts it into a URL. Instead of passing a JSON string, for example, you could just construct a URL containing the transfer object.

Since it assumes you are making GET calls, RESTful design would suggest only using UED for non-destructive calls (i.e. calls that don’t change server state).

A hash is encoded like this:

JAVASCRIPT:

  1.  
  2. //The JS Array format of the example given above
  3. var arr = {
  4.         ‘name’:”Binny”,
  5.         ‘year’:2007,
  6.         ‘quote’:”Hello, World!”,
  7.         ‘os’:[’Windows’,'Linux’,'Mac’],
  8.         ’software’:{
  9.                 ‘editor’:”vi”,
  10.                 ‘audio’:”xmms”,
  11.                 ‘video’:”vlc”
  12.         }
  13. }
  14. var data = ued_encode(arr);
  15.  

leading to a URL like this:

JAVASCRIPT:

  1.  
  2. http://www.example.com/get_data.php?name=Binny&year=2007&
  3. quote=Hello%2C+World%21&os[]=Windows&os[]=Linux&os[]=Mac&
  4. software[editor]=vi&software[audio]=xmms&software[video]=vlc
  5.  

However, there are no server-side decoders as yet.

Source: Ajaxian
Original Article: http://ajaxian.com/archives/ued-url-encoded-data

Leave a Reply

You must be logged in to post a comment.



Site Navigation