Showing posts with label dom. Show all posts
Showing posts with label dom. Show all posts

Tuesday, March 07, 2017

REST / RESTful Web Service Interview Questions - Part 1

What REST stands for?
REST stands for REpresentational State Transfer.

What is REST?
REST is web standards based architecture and uses HTTP Protocol for data communication. It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods. REST was first introduced by Roy Fielding in 2000.
In REST architecture, a REST Server simply provides access to resources and REST client accesses and presents the resources. Here each resource is identified by URIs/ global IDs. REST uses various representations to represent a resource like text, JSON and XML. Now a days JSON is the most popular format being used in web services.

Name some of the commonly used HTTP methods used in REST based architecture?
Following well known HTTP methods are commonly used in REST based architecture −
GET − Provides a read only access to a resource.
PUT − Used to create a new resource.
DELETE − Ued to remove a resource.
POST − Used to update a existing resource or create a new resource.
OPTIONS − Used to get the supported operations on a resource.




What is web service?
A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks like the Internet in a manner similar to inter-process communication on a single computer.

What are RESTful webservices?
Web services based on REST Architecture are known as RESTful web services. These web services use HTTP methods to implement the concept of REST architecture. A RESTful web service usually defines a URI, Uniform Resource Identifier a service, provides resource representation such as JSON and set of HTTP Methods.

What is a Resource in REST?
REST architecture treats every content as a resource. These resources can be text files, html pages, images, videos or dynamic business data. REST Server simply provides access to resources and REST client accesses and modifies the resources. Here each resource is identified by URIs/ global IDs.

How to represent a resource in REST?
REST uses various representations to represent a resource where text, JSON, XML. XML and JSON are the most popular representations of resources.

What are the best practices to design a resource representation?
Following are important points to be considered while designing a representation format of a resource in a RESTful web services −
Understandability − Both Server and Client should be able to understand and utilize the representation format of the resource.
Completeness − Format should be able to represent a resource completely. For example, a resource can contain another resource. Format should be able to represent simple as well as complex structures of resources.
Linkablity − A resource can have a linkage to another resource, a format should be able to handles such situations.

Which protocol is used by RESTful webservices?
RESTful web services make use of HTTP protocol as a medium of communication between client and server.

What is messaging in RESTful webservices?
A client sends a message in form of a HTTP Request and server responds in form of a HTTP Response. This technique is termed as Messaging. These messages contain message data and metadata i.e. information about message itself.


What is addressing in RESTful webservices?
Addressing refers to locating a resource or multiple resources lying on the server. It is analogous to locate a postal address of a person.

What is URI?
URI stands for Uniform Resource Identifier. Each resource in REST architecture is identified by its URI.

What is purpose of a URI in REST based webservices?
Purpose of an URI is to locate a resource(s) on the server hosting the web service.

What is format of a URI in REST architecture?
A URI is of following format −
<protocol>://<server-address:port>/<service-name>/<ResourceType>/<ResourceID>

What is the purpose of HTTP Verb in REST based webservices?
VERB identifies the operation to be performed on the resource.

What are the best practices to create a standard URI for a web service?
Following are important points to be considered while designing a URI −
Use Plural Noun − Use plural noun to define resources. For example, we've used users to identify users as a resource.
Avoid using spaces − Use underscore(_) or hyphen(-) when using a long resource name, for example, use authorized_users instead of authorized%20users.
Use lowercase letters − Although URI is case-insensitive, it is good practice to keep url in lower case letters only.
Maintain Backward Compatibility − As Web Service is a public service, a URI once made public should always be available. In case, URI gets updated, redirect the older URI to new URI using HTTP Status code, 300.
Use HTTP Verb − Always use HTTP Verb like GET, PUT, and DELETE to do the operations on the resource. It is not good to use operations names in URI.



What is statelessness in RESTful Webservices?
As per REST architecture, a RESTful web service should not keep a client state on server. This restriction is called statelessness. It is responsibility of the client to pass its context to server and then server can store this context to process client's further request. For example, session maintained by server is identified by session identifier passed by the client.

What are the advantages of statelessness in RESTful Webservices?
Following are the benefits of statelessness in RESTful web services −
·         Web services can treat each method request independently.
·         Web services need not to maintain client's previous interactions. It simplifies application design.
·         As HTTP is itself a statelessness protocol, RESTful Web services work seamlessly with HTTP protocol.

What are the disadvantages of statelessness in RESTful Webservices?
Following is the disadvantage of statelessness in RESTful web services −
·         Web services need to get extra information in each request and then interpret to get the client's state in case client interactions are to be taken care of.

What do you mean by idempotent operation?

Idempotent operations means their result will always same no matter how many times these operations are invoked.


Refer to Part 2 of the interview questions set at below URL

http://osb-dheeraj.blogspot.in/2017/03/rest-restful-web-service-interview.html




REST / RESTful Web Service Interview Questions - Part 2


Which type of Webservices methods are to be idempotent?
PUT and DELETE operations are idempotent.

Which type of Webservices methods are to be read only?
GET operations are read only and are safe.

What is the difference between PUT and POST operations?
PUT and POST operation are nearly same with the difference lying only in the result where PUT operation is idempotent and POST operation can cause different result.

What should be the purpose of OPTIONS method of RESTful web services?
It should list down the supported operations in a web service and should be read only.

What should be the purpose of HEAD method of RESTful web services?
It should return only HTTP Header, no Body and should be read only.

What is caching?
Caching refers to storing server response in client itself so that a client needs not to make server request for same resource again and again. A server response should have information about how a caching is to be done so that a client caches response for a period of time or never caches the server response.

Which header of HTTP response, provides the date and time of the resource when it was created?
Date header provides the date and time of the resource when it was created.

Which header of HTTP response, provides the date and time of the resource when it was last modified?
Last Modified header provides the date and time of the resource when it was last modified.

Which header of HTTP response provides control over caching?
Cache-Control is the primary header to control caching.

Which header of HTTP response sets expiration date and time of caching?
Expires header sets expiration date and time of caching.

Which directive of Cache Control Header of HTTP response indicates that resource is cachable by any component ?
Public directive indicates that resource is cachable by any component.

Which directive of Cache Control Header of HTTP response indicates that resource is cachable by only client and server, no intermediary can cache the resource?
Private directive indicates that resource is cachable by only client and server, no intermediary can cache the resource.

Which directive of Cache Control Header of HTTP response indicates that resource is not cachable ?
no-cache/no-store directive indicates that resource is not cachable.

Which directive of Cache Control Header of HTTP response can set the time limit of caching ?
max-age directive indicates that the caching is valid up to max-age in seconds. After this, client has to make another request.

Which directive of Cache Control Header of HTTP response provides indication to server to revalidate resource if max-age has passed ?
must-revalidate directive provides indication to server to revalidate resource if max-age has passed.

What are the best practices for caching ?
Always keep static contents like images, css, JavaScript cacheable, with expiration date of 2 to 3 days. Never keep expiry date too high.
Dynamic contents should be cached for few hours only.

What are the best practices to be followed while designing a secure RESTful web service ?
As RESTful web services work with HTTP URLs Paths so it is very important to safeguard a RESTful web service in the same manner as a website is be secured. Following are the best practices to be followed while designing a RESTful web service −
Validation − Validate all inputs on the server. Protect your server against SQL or NoSQL injection attacks.
Session based authentication − Use session based authentication to authenticate a user whenever a request is made to a Web Service method.
No sensitive data in URL − Never use username, password or session token in URL , these values should be passed to Web Service via POST method.
Restriction on Method execution − Allow restricted use of methods like GET, POST, DELETE. GET method should not be able to delete data.
Validate Malformed XML/JSON − Check for well formed input passed to a web service method.
Throw generic Error Messages − A web service method should use HTTP error messages like 403 to show access forbidden etc.

What is the purpose of HTTP Status Code ?
HTTP Status code are standard codes and refers to predefined status of task done at server. For example, HTTP Status 404 states that requested resource is not present on server.

What is JAX-RS ?
JAX-RS stands for JAVA API for RESTful Web Services. JAX-RS is a JAVA based programming language API and specification to provide support for created RESTful Webservices. Its 2.0 version was released in 24 May 2013. JAX-RS makes heavy use of annotations available from Java SE 5 to simplify development of JAVA based web services creation and deployment. It also provides supports for creating clients for RESTful web services.

What are the core components of a HTTP Request?
A HTTP Request has five major parts −
Verb − Indicate HTTP methods such as GET, POST, DELETE, PUT etc.
URI − Uniform Resource Identifier (URI) to identify the resource on server.
HTTP Version − Indicate HTTP version, for example HTTP v1.1 .
Request Header − Contains metadata for the HTTP Request message as key-value pairs. For example, client ( or browser) type, format supported by client, format of message body, cache settings etc.
Request Body − Message content or Resource representation.




What are the core components of a HTTP response?
A HTTP Response has four major parts −
Status/Response Code − Indicate Server status for the requested resource. For example 404 means resource not found and 200 means response is ok.
HTTP Version − Indicate HTTP version, for example HTTP v1.1 .
Response Header − Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc.
Response Body − Response message content or Resource representation.



Sunday, February 21, 2016

SOA Interview Questions : Service Oriented Architecture Interview Questions Part 5



What is a Complex XML Element?

A complex element is an XML element that contains other elements and/or attributes.
There are four kinds of complex elements:
empty elements
elements that contain only other elements
elements that contain only text
elements that contain both other elements and text


What is a Simple XML Element?

A simple element is an XML element that can contain only text.
A simple element cannot have attributes
A simple element cannot contain other elements
A simple element cannot be empty
However, the text can be of many different types, and may have various restrictions applied to it.


What is XPATH ?

XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document.
The XPath language is based on a tree representation of the XML document, and provides the ability to navigate around the tree, selecting nodes by a variety of criteria.

XPATH  Syntax & Operators ?
Expression
Description
nodename
Selects all nodes with the name "nodename"
/
Selects from the root node
//
Selects nodes in the document from the current node that match the selection no matter where they are
.
Selects the current node
..
Selects the parent of the current node
@
Selects attributes
*
Matches any element node
@*
Matches any attribute node
node()
Matches any node of any kind



Example of some XPath Expressions ?

Example XML document
<?xml version="1.0" encoding="UTF-8"?>
<books>
                <book>
                                <title lang="en">Harry Potter</title>
                                <price>29.99</price>
                </book>
                <book>
                                <title lang="en">Learning XML</title>
                                <price>39.95</price>
                </book>
</books>


Example XPATH expressions and Result

Path Expression
Result
/books/book[1]
Selects the first book element that is the child of the books element.
/books/book[last()]
Selects the last book element that is the child of the books element
//title[@lang]
Selects all the title elements that have an attribute named lang
//title[@lang='en']
Selects all the title elements that have a "lang" attribute with a value of "en"
/books/book[price>35.00]
Selects all the book elements of the books element that have a price element with a value greater than 35.00



What is XSLT ?

XSLT (Extensible Stylesheet Language Transformations) is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or into XSL Formatting Objects.
The original document is not changed; rather, a new document is created based on the content of an existing one. Typically, input documents are XML files.


Example XSLT code ?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/persons">
    <root>
      <xsl:apply-templates select="person"/>
    </root>
  </xsl:template>
</xsl:stylesheet>



XSLT vs XPATH ?

XSLT uses XPath to identify subsets of the source document tree and perform calculations.
XPath also provides a range of functions, which XSLT itself further augments.



How to refer another XSL from main XSL file ?

The <xsl:import> element is a top-level element that is used to import the contents of one style sheet into another.

Note: This element must appear as the first child node of <xsl:stylesheet> or <xsl:transform>.
Syntax: <xsl:import href="URI"/>


Why we use Call-template inside XSL ?

Call-template works similar to the apply-template element in XSLT. Both attach a template to specific XML data. This provides formatting instructions for the XML. The main difference between the two processes is the call function only works with a named template. You must establish a 'name' attribute for the template in order to call it up to format a document.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
< xsl:call-template name="myTemplate">
< !-- Content: xsl -->
< /xsl:call-template>

< stylesheet>




Refer Previous post on Interview questions at

1. SOA Interview Questions : Service Oriented Architecture Interview Questions Part 1

http://osb-dheeraj.blogspot.com/2016/02/soa-interview-questions-service.html

2. SOA Interview Questions : Service Oriented Architecture Interview Questions Part 2


http://osb-dheeraj.blogspot.com/2016/02/soa-interview-questions-service_16.html

3. SOA Interview Questions : Service Oriented Architecture Interview Questions Part 3

http://osb-dheeraj.blogspot.com/2016/02/soa-interview-questions-service_21.html

4. SOA Interview Questions : Service Oriented Architecture Interview Questions Part 4

http://osb-dheeraj.blogspot.com/2016/02/soa-interview-questions-service_77.html


SOA Interview Questions : Service Oriented Architecture Interview Questions Part 4



What is XML ?

Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format which is both human-readable and machine-readable. It is defined by the W3C's XML 1.0 Specification
The design goals of XML emphasize simplicity, generality and usability across the Internet. XML was designed to store and transport data, and designed to be self-descriptive.


Sample XML file ?

<?xml version="1.0" encoding="UTF-8"?>
<Message>
    <MessageID>1</MessageID>
    <Operation>Update</Operation>
    <Inventory>                                      
         <Quantity>55</Quantity>          
    </Inventory>
</Message>



What are Main Key Terminology of XML ?

Tag
A markup construct that begins with < and ends with >. Tags come in three flavors:
start-tags; for example: <section>
end-tags; for example: </section>
empty-element tags; for example: <section/>

Element
A logical document component which either begins with a start-tag and ends with a matching end-tag or consists only of an empty-element tag.
The characters between the start- and end-tags, if any, are the element's content, and may contain markup, including other elements, which are called child elements.
An example of an element is
<Greeting>Hello, world</Greeting>
Another is
<line-break />

Attribute
A markup construct consisting of a name/value pair that exists within a start-tag or empty-element tag.
In the example (below) the element img has two attributes, src and desc:
<img src="myimage.jpg" desc='my image' />



What is Data Object model (DOM) ?

The Document Object Model (DOM) is an interface-oriented application programming interface that allows for navigation of the entire document as if it were a tree of node objects representing the document's contents. A DOM document can be created by a parser, or can be generated manually by users.



What is difference between XML & HTML ?

XML was developed to describe data and to focalize on what the data represent.
HTML was developed to display data about to focalize on the way that data looks.
HTML is about displaying data, XML is about describing information.
XML is extensible.The tags used to mark the documents and the structures of documents in HTML are pre-defined.
The author of HTML documents can use only tags that were previously defined in HTML.
The Standard XML gives you the possibility to define personal structures and tags.



What is XML Schema (XSD) ?

An XML Schema describes the structure of an XML document. XSD (XML Schema Definition) is the language used to describe schema. They use a rich datatyping system and allow for more detailed constraints on an XML document's logical structure.


Write a sample Schema File ?

<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.org"
            targetNamespace="http://www.example.org" elementFormDefault="qualified">
  <xsd:element name="exampleElement" type="xsd:string">
    <xsd:annotation>
      <xsd:documentation>A sample element</xsd:documentation>
    </xsd:annotation>
  </xsd:element>
</xsd:schema>





What is Inline schema ?

Inline schemas are a way of including the schema within a WSDL file rather than specifying that it be imported. A schema defines the structure of an XML document. A schema is itself an XML document defined with an xsd extension.


Difference between Include and Import in context to XML schema ?

The fundamental difference between include and import is that you must use import to refer to declarations or definitions that are in a different target namespace and you must use include to refer to declarations or definitions that are (or will be) in the same target namespace.



What Is XML Namespace ?

XML namespaces are used for providing uniquely named elements and attributes in an XML document. They are defined in a W3C recommendation. XML Namespaces enable the same document to contain XML elements and attributes taken from different vocabularies, without any naming collisions occurring.
An XML namespace is declared using the reserved XML attribute xmlns or xmlns:prefix,
xmlns:xhtml="http://www.w3.org/1999/xhtml"


What is targetNamespace ?

<schema xmlns="http://www.w3.org/2001/SchemaXML         targetNamespace="http://www.example.com/name"         xmlns:target="http://www.example.com/name">

The targetNamespace declares a namespace for other xml and xsd documents to refer to this schema. The target prefix in this case refers to the same namespace and you would use it within this schema definition to reference other elements, attributes, types, etc. also defined in this same schema definition.


What is ElementFormDefault ?

The form for elements declared in the target namespace of this schema. The value must be "qualified" or "unqualified". Default is "unqualified". "unqualified" indicates that elements from the target namespace are not required to be qualified with the namespace prefix. "qualified" indicates that elements from the target namespace must be qualified with the namespace prefix.


What is AttributetFormDefault ?


The form for attributes declared in the target namespace of this schema. The value must be "qualified" or "unqualified". Default is "unqualified". "unqualified" indicates that attributes from the target namespace are not required to be qualified with the namespace prefix. "qualified" indicates that attributes from the target namespace must be qualified with the namespace prefix.




Refer Previous post on Interview questions at

1. SOA Interview Questions : Service Oriented Architecture Interview Questions Part 1

http://osb-dheeraj.blogspot.com/2016/02/soa-interview-questions-service.html

2. SOA Interview Questions : Service Oriented Architecture Interview Questions Part 2

http://osb-dheeraj.blogspot.com/2016/02/soa-interview-questions-service_16.html

3. SOA Interview Questions : Service Oriented Architecture Interview Questions Part 3

http://osb-dheeraj.blogspot.com/2016/02/soa-interview-questions-service_21.html