RESTFul Technique

RESTFul means Representational State Transfer. In a REST approach, servers communicate with clients using stateless connections. All the information about the state of the interaction
between the two is encoded into the requests and responses between them. Long-term state is kept on the server as a set of identifiable resources. Clients access these resources using a well-defined set of resource identifiers . REST distinguishes the content of resources from the presentation of that content. RESTFul technique abandoned server based sessions.

Difference Between RESTFul technique and SOAP/XML-RPC system……..

  • Clients in a RESTFul system are required to submit all the information which are necessary to process a request in a header.
  • In SOAP (Simple Object Access Protocol) or XML-RPC system, the body of the message need not to be examined for the server in order to route it to the proper segment of the code.

Extra Features of RESTFul technique

1. Resources and requirement of a uniform interface :

Resources are the heart of the four requirements of the RESTFul uniform interfaces –>

  • Resource identification
  • Resource manipulation via representation
  • Self descriptive messaging
  • Use of hypermedia as the engine of application state.

2. Layerd systems :

The layered system requires that each component in the chain between client and server knows about only its immediate neighbors.

3. Code-on-demand :

With this feature clients of a RESTFul application can be modified on-the-fly by downloading only the additional functional code from the server. [ It is a topic that has not yet
been addressed in the Rails community, though it opens up possibilities of client extensibility
that may make it worthwhile to work toward
].

More on………  Apress Practical REST on Rails 2

How to Create Interface ??

In ruby basically we have no built in option for creating Interface. We just need to force the base class method to act like an Interface method.

Example :–>

class InterfaceName

def show

raise ‘Exception! This method must be implemented before accessing it.’

end

end

—————————

class SubclassName < InterfaceName

….

end

————————

If we want to do the following then it raises Exception…

SubclassName . show

Marshaling of Object

Marshalling is an interesting thing. Marshaling is the process by which object can be converted into byte streams  and stored outside the application. So, we can use/read this saved object from another application and copy of the originally saved object can be reconstituted.

Rails uses marshalling for storing session data.

Remind me while working with Database

Performance tune of database………..

  • Denormalize your database where appropriate.
  • Proper use of index columns : An index based on numeric fields is more efficient than an index based on character columns.
  • Reduce the number of columns that make a composite key.
  • Proper partitioning of table spaces and create a special tablespace for special data types.
  • Data access performance can be tuned by using stored procedure to break up data in the database server to reduce the network overhead and also caching data within your application to reduce the number  of accesses.

Refactoring

What is Refactoring?

Refactoring is the process of changing a software system in such a way so that it does not alter the external behavior of  the code and improves the internal structure in a efficient way. It is a way of clean up code and improve the design of code after writting the code. It minimizes the chance of introducing bugs.

Techniques of  Refactoring:

  • Composing Methods.
  • Moving features between objects.
  • Organizing data.
  • Simplifying conditional expressions.
  • Making method calls simpler.
  • Dealing with generalization.
Details…
Refactoring Improving the Design of Existing Code (by… Martin Fowler,William Opdyke).

Components of Rails

Rails consisted of following components…….

  • Action controller–>Session Management, Template Rendering.
  • Action view–>HTML and XML output.
  • Active record–>Base for models, CRUD.
  • Action mailer–>E-mail services.
  • Active resource–>RESTFul web services.
  • Railities–>Incorporate various framework together.
  • Active support–>Utility classes and library extensions.

Basics of Ruby

Ruby is an object oriented programming Language. It is dynamic in nature. Basically it has no primitive data types. It has no built in supports of Interface as dose Java.

Variable Declaration :

  • local variable–> varname.
  • instance variable–> @varname.
  • global variable–> $varname.
  • class variable–> @@varname.

Class method Definition :

def ClassName. methodName
end

def  self. methodName
end

class << self
def methodName

end
end

Inheritance :

class SubclassName < SuperclassName
end

Ruby code block :

objectName . Method do

|object|  puts(object.value)

end

Name Spaces:

The double colone(::) is Ruby’s namespace resolution operator. The thing to the left must be a class or module and the thing to the right is a constant which is defined in that class or module.

Example :–> Math :: pi.

Attribute accessor methods :

  • Attribute setting method

attr_writer :duration

  • Attribute getting method

attr_reader :name, :artist

Read the rest of this entry »