Sunday, 30 September 2012

Advanced REST client API

API it's a big word for that but in some part you can call it an API :)

If you are an author of an extension and  you would like to use my application now it is possible.
When your application would like to open a request data in Advanced REST client you have two possibilities:

  1. using chrome message passing system
  2. using webIntents (you don't need to have a chrome extension)
You just need to pass request object with following data:
"payload" (required) - message payload: 
  • "create" to open new application window with values; 
  • other payloads may be available in future
"data" - (required) javascript object with any of values:
  • url - (String) request URL to set
  • method - (String) request method to set
  • headers - (String) an RFC string representing request headers example:
    >>> User-Agent: X-Extension
    X-header: header value; second value <<< 
  • payload - (String) data to pass into payload field. Only for http methods that carry payload data
  • encoding - (String) data form encoding
Example of usage:

var message = { 
   'payload': 'create', 
   'data': { 
       'url': 'http://www.google.com/', 
       'method': 'GET', 
       'headers': "User-Agent: Chrome-Extension\nX-extension-id: SomeID" 
    } 
};
Via extensions message passing system:
chrome.extension.sendMessage("hgmloofddffdnphfgcellkdfbfbjeloo", message, function(response) {});


Using webIntents:


window.Intent = window.Intent || window.WebKitIntent;
window.navigator.startActivity = window.navigator.startActivity ||
window.navigator.webkitStartActivity;
 
var params = { 
   "action": "http://webintents.org/view", 
   "type": "application/restclient+data" , 
   "data": message 
}; 
var i = new WebKitIntent(params); 
var onSuccess = function(data) { console.log(data); };
var onFailure = function() { console.log('intent error'); };
navigator.webkitStartActivity(i, onSuccess, onFailure);
For more information check trunk: http://code.google.com/p/chrome-rest-client/source/browse/trunk/RestClient/war/extension/background.js

Why do I need "history" permissions?

Well, It's quite simple.
When you start typing a URL, the application doing two things: search application history for given URL and query browsers history.
Searching application history is obvious. But chrome history is not.
In fact it just query your history with query you entered to URL field and displays results in suggestions dialog.


If you ever visits this url it will be displayed in list so you can your job faster :) I know that probably you just paste URL in this field but I think is a good feature anyway. It do nothing else with your data. You can check trunk to see what it actually doing with history data: http://code.google.com/p/chrome-rest-client/source/browse/trunk/RestClient/src/org/rest/client/suggestion/UrlsSuggestOracle.java

Cheers!

Friday, 21 September 2012

It's almost here! New version of Advanced Rest Client

Hi all!

I'd like to inform you that new version of the application is almost ready :)
It took over 3 months but the application was written from scratch. Now it can do a lot more than current version. Thanks for all who submit an issue on http://code.google.com/p/chrome-rest-client/issues/list and helps me improve application.

Note:
There is a number of new permissions required by the application. See bottom of this post for more info.

Let's start from UI.

New version UI

UI now have more modern look. It is not very different from current version, but devil is in the details. Have you noticed that there is new option in menu?

Projects is a new feature. It helps you organize saved requests and you can easily switch between requests sharing it's parameters. More about projects you can find in my previous post.
Project view
OK, let's make a HTTP request:


Still it is not very different form previous version. But as you can see I've added new section to response view. Now Request Headers are also available in application view. And there is more.
Since now you can overwrite browsers headers that are not available for regular XmlHttpRequest! This mean that you can set User-Agent, Accept and many more headers. It becomes possible since new declarativeWebRequest API in Chrome. And here is the bad news. For today it is only available for Chrome Dev Channel (version 23). It will take about 3 months before it becomes available in stable version. Since then I'll send an update to Web Store but it will be available for version 23+.

Let's go on. Lately someone suggest that application should show redirect chain (issiue 67). Well, here it is:

It will show complete request flow. For each redirect it collects information about received headers, status and information is this redirection comes from cache (f.e. HTTP 301) or not.


I've made some improvements to request form panel. You can "open" url input field and create URL using form:
When you need to encode query parameters just pres "enc" button for this parameter. If you need to encode parameter but replace + with %20 just hold CTRL key.


There are changes in settings section as well. First at all "cookies capture" is no more experimental. Well, it is not working very well right now. Results may vary and you can't rely on it. But since application can show all response headers (even those invisible to the XmlHttpRequest object) you can see cookie data in response panel.
There is no JSON headers settings. This is fixed now and list contain all popular json headers definitions.

Important change for the application is import/export options. Since now export to application server is deprecated and this option will be removed December 1st, 2012.
There are better options for import export. First is export to file. Application will generate json file with projects and requests definitions. You can easily change it's content and send file to collaborators. Thanks to this change you don't need to be worry about data sent to application server.

Next step it to implement Google Drive API to save file directly on your drive. Then the application becomes one of the Google Drive applications.

There is a number of new permissions required by application.

  • webRequest 
    • This is required to observe and analyze traffic - to know when redirect occur and to catch request and response headers 
  • declarativeWebRequest 
    • This is required to modify request headers by XmlHttpRequest (to remove or add headers)
  • background 
  • storage 
    • Chrome provides API for sync data. Application will synchronize some settings like debug and history options.
  • history (not changed) is required by URL widget to provide fill support. While typing an URL it search application's and browser's history. When it find matches it will return it in suggestions list. Browser's history is not stored in application
  • <all_urls> (not changed) is required by application to make any request outside application sandbox. 
  • cookies permission has been removed

I hope you like changes and you will like new version of the application. Update will become available in next few weeks. Since then you still can report an issue if you found some :)

Cheers!