Introduction

Restful web service encourages using HTTP.  That means the client that can talk HTTP will be able to consume the service. For the web, the tool that usually is JavaScript so that make sense to use JavaScript as a client programming language to built the application.

We can use a JavaScript with its HTTP request library to consume the service. Anyway, using library will reduce the development time. Today I will show you how use ExtJS JavaScript framework with Restful service.

Making HTTP Request

Below is example to make a HTTP PUT,

Ext.Ajax.request({
url: '/posts/',
form: 'post_form',
method:'put', params: {
author: 'Meledictas',
subject: 'Comsume RESTful Web Services using ExtJS'}, success: function(response, opts) {
var obj = Ext.decode(response.responseText);
},
failure: function(response, opts) {
console.log('Server side failure with status code ' + response.status);
}
});

Setting up the HTTP Header

You can define the HTTP Header like this,

var header = Ext.Ajax.defaultHeaders = {
'Accept': 'application/json'
};

And in your request code,

Ext.Ajax.request({
   defaultHeaders: header 
,
});

That all! Enjoy Restful!

Comsume RESTful Web Services using ExtJS

Comments:

Is there a way to set the header in httpproxy/scripttagproxy?

Post your comment:

Author:

  • meledictas

Archives:

Powered by Django.