0% found this document useful (0 votes)
152 views25 pages

Lecture 9 APIs and Web Services

Uploaded by

fadila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views25 pages

Lecture 9 APIs and Web Services

Uploaded by

fadila
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Application Programming Interfaces

(APIs) and Web Services


ISM301
Lecture 9
Application Programming Interface (API)
• API stands for Application Programming Interface.
• It is a software intermediary that allows two applications to talk to each
other. In other words, an API is the messenger that delivers your request
to the provider that you’re requesting it from and then delivers the
response back to you.
• It is a software-to-software interface, not a user interface.
• With API, applications talk to each other without any user knowledge or
intervention.
• Note: Main goal of API is code/program reusable. An API resembles
Software as a Service (SaaS), since software developers don’t have to start
from scratch every time they write a program.
• Instead of building one core application that tries to do everything, the
same application can contract out certain responsibilities to remote
software that does it better.
Types of API
• Local API: is the original form of API which is the OS APIs that provide
services to application programs (Front-end/GUI) requesting services
or data from the back-end such as voice service or data from DB.
Microsoft’s .NET APIs, the TAPI (Telephone API) for voice applications,
and database access APIs are examples of the local API form.
• Program API: is based on RPC (Remote Procedure Call) technology
that making a remote program execution from another servers. SOA
(Service Oriented Architecture) APIs such as Microsoft's WS-series of
API are samples of Program API.
• Web API: also known as Web Service, is application/device
communicate to each other via World Wide Web (HTTP architecture).
Types of APIs
• APIs take three basic forms: private, public and partner.
Private APIs or internal APIs - are published internally for use by
the company’s developers to improve its own products and
services. Private APIs are not exposed to third parties.
Public APIs or open APIs - are published publicly and can be used
by any third-party. There are no restrictions on these APIs.
Partner APIs - can only be used by specific parties with whom the
company agrees to share data. Partner APIs are used within
business relationships, often to integrate software between
partnering companies.
Benefits of Using APIs
There are many benefits of using APIs which include:
• Private APIs can improve internal development processes by
standardizing how developers write application code.
• Using the same rules and formats can make code more
streamlined and transparent.
• Standardization also facilitates collaboration between
developers as they build software components with the
intent to integrate with APIs. This, in turn, can support
feature development and reduce time to market.
API in Developer Community
• The internet is currently the primary driver for APIs,
and companies like Facebook , Google and
Yahoo publish APIs to encourage developers to build
on their capabilities. These APIs have given us
everything from new internet features that browse
the sites of other services, to mobile device apps that
offer easy access to web resources.
• New features, such as content delivery, augmented
reality and novel applications of wearable technology,
are created in large part through these APIs.
API Economy
• API economy (application programming interface economy): is a
general term that describes the way application programming
interfaces (APIs) can positively affect an organization's profitability.
An API is a customer interface for technology products that allows
software components to communicate.
• There was a time when only software professionals knew about APIs.
Today, business leaders are aware of the financial impact APIs can
have and companies are generating revenue by exposing APIs as
business building blocks for third party applications.
• The emerging financial effects of APIs on businesses have gained
steam thanks in part to mobile and social media technologies. Major
companies that have gained revenue from APIs include
SalesForce.com, Amazon, Facebook, Twitter, and Google.
Web service
• Web service is a means by which computers talk to each other over
the web using HTTP and other universally supported protocols.
• A web service is a software module which is designed to perform a
certain set of tasks.
• The web services can be searched for over the network and can also
be invoked accordingly.
• When invoked the web service would be able to provide functionality
to the client which invokes that web service.
The diagram shows a very simplistic view of how a web service would
actually work. The client would invoke a series of web service calls
via requests to a server which would host the actual web service.
These requests are made through what is known as remote
procedure calls. Remote Procedure Calls(RPC) are calls made to
methods which are hosted by the relevant web service.
Web service
• The main component of a web service is the data which is transferred
between the client and the server, and that is XML.
• So when applications talk to each other, they actually talk in XML. This
provides a common platform for application developed in various
programming languages to talk to each other.
• Web services use something known as SOAP (Simple Object Access
Protocol) for sending the XML data between applications. The data is
sent over normal HTTP. The data which is sent from the web service
to the application is called a SOAP message. The SOAP message is
nothing but an XML document. Since the document is written in XML,
the client application calling the web service can be written in any
programming language.
Web service Characteristics

• They are XML-Based


• Loosely Coupled
• Synchronous or Asynchronous functionality
• Ability to support Remote Procedure Calls
(RPCs)
• Supports Document Exchange
Web Services Architectures
The simplest Web service system has two participants:
• A service producer (provider) - The provider creates the web service
and makes it available to client application who want to use it.
• A service consumer (requester) - A requestor is nothing but the client
application that needs to contact a web service. The client application
can be a .Net, Java, or any other language based application which
looks for some sort of functionality via a web service.
Web Services Architectures
A more sophisticated system:
• A registry or broker The broker is nothing but the application which
provides access to the UDDI. The UDDI enables the client application
to locate the web service.
• A provider, can publish services to the registry
• A consumer, can then discover services in the registry
1.Publish - A provider informs the broker (service
registry) about the existence of the web service by
using the broker's publish interface to make the
service accessible to clients
2.Locate- The requestor consults the broker to locate
a published web service
3.Bind - With the information it gained from the
broker(service registry) about the web service, the
requestor is able to bind, or invoke, the web service.
Type of Web Service
There are mainly two types of web services.
• SOAP web services.
• RESTful web services.
SOAP Web Service
• Describes a standardized way of integrating Web-based
applications using
the XML, SOAP, WSDL and UDDI open standards over an Internet
protocol backbone.
• Mechanism for defining the unit of communication and error
handling.
• Sent via HTTP, which is the standard web protocol.
• The root element of a SOAP message is the <Envelope> element.
• The "envelope" is divided into 2 parts: the header, and the body.
• Header contains routing data which is the information which tells
the XML document to which client it needs to be sent to.
• The body will contain the actual message.
• Elements called Faults can be used to describe exceptional
eXtensible Markup Language (XML)
• The eXtensible Markup Language (XML) is a W3C recommendation for
creating special-purpose markup languages that enable the
structuring, description and interchange of data.
• A simplified subset of SGML capable of describing many different
kinds of data for any imaginable application domain.
• It facilitates the sharing of structured text and information in
databases and across the Internet.
• Languages based on XML are themselves described in a formal way,
allowing programs to modify and validate documents in these
languages without prior knowledge of their form.
• Separate syntax from semantics.
• Inherently supports internationalization (Unicode) and platform
independence.
XML Building Blocks
• Elements - The pairing of a start tag and an end tag.
• Attributes - A name-value pair that is part of a starting tag of an Element.
• Processing Instructions - Special directives to the application that will process the XML document.
• Comments - Messages helping a human reader understand the source code.
• Character Data - Characters (in a specific encoding), Entities and Whitespace.
• Production Rule
<element> ::= <EmptyElement>
| <STag> <content> <ETag>
<STag> ::= ‘<‘ <Name> <Attribute>* ’>’
<ETag> ::= ‘</‘ Name ‘>’
<EmptyElement> ::= ‘<‘ Name <Attribute>* ’/>’
• XML Elements must be strictly nested!
• Element names can include letters, the underscore,
hyphen and colon; they must begin with a letter.
• Element names are case sensitive!
Web Services Description Language
WSDL is an XML-based language for describing web services and how to
access them.
• WSDL is an XML based protocol for information exchange in
decentralized and distributed environments.
• Standard format for describing a web service.
• Describes how to access a web service and what operations it will
perform.
• A language for describing how to interface with XML-based services.
• integral part of UDDI, an XML-based worldwide business registry.
• Language that UDDI uses.
WSDL Documents
• An WSDL document describes a web service. It specifies the location
of the service, and the methods of the service, using these major
elements:
Element Description

<types> Defines the (XML Schema) data types used by the web
service

<message> Defines the data elements for each operation

<portType> Describes the operations that can be performed and the


messages involved.

<binding> Defines the protocol and data format for each port type
WSDL Documents
• An example of a WSDL file is given below.
<definitions>
<message name="TutorialRequest">
<part name="TutorialID" type="xsd:string"/>
</message>
<message name="TutorialResponse"> <part name="TutorialName" type="xsd:string"/> </message>

<portType name="Tutorial_PortType">
<operation name="Tutorial">
<input message="tns:TutorialRequest"/>
<output message="tns:TutorialResponse"/> </operation> </portType>
<binding name="Tutorial_Binding" type="tns:Tutorial_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Tutorial">
<soap:operation soapAction="Tutorial"/> <
input> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:Tutorialservice" use="encoded"/> </input>
<output> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:Tutorialservice" use="encoded"/> </output> </operation> </binding> </definitions>
WSDL Documents
• The important aspects to note about the above WSDL declaration are
as follows;
• <message> - The message parameter in the WSDL definition is used to define
the different data elements for each operation performed by the web service.
So in the example above, we have 2 messages which can be exchanged
between the web service and the client application, one is the
"TutorialRequest", and the other is the "TutorialResponse" operation. The
TutorialRequest contains an element called "TutorialID" which is of the type
string. Similarly, the TutorialResponse operation contains an element called
"TutorialName" which is also a type string.
• <portType> - This actually describes the operation which can be performed
by the web service, which in our case is called Tutorial. This operation can
take 2 messages; one is an input message, and the other is the output
message.
• <binding> - This element contains the protocol which is used. So in our case,
we are defining it to use http (http://schemas.xmlsoap.org/soap/http). We
also specify other details for the body of the operation, like the namespace
Universal Description, Discovery, and
Integration (UDDI)
• standard for describing, publishing, and discovering the web services that are
provided by a particular service provider.
• provides a specification which helps in hosting the information on web services.
• Platform independent, open framework.
• Uses WSDL to describe interfaces to web services.
• Seen with SOAP and WSDL as one of the three foundation standards of web
services.
• Open industry initiative enabling businesses to discover each other and define
how they interact over the Internet.
• Just as a telephone directory has the name, address and telephone number of a
particular person, the same way the UDDI registry will have the relevant
information for the web service. So that a client application knows, where it can
be found.
RESTful
• RESTful (REpresentational State Transfer) Web Service: also known as
RESTful API, is based on REST technology which is an web application
that uses HTTP requests to GET, PUT, POST and DELETE data.
• REST technology is generally preferred to the more robust Simple
Object Access Protocol (SOAP) technology because REST leverages
less bandwidth, making it more suitable for internet usage.
• With cloud use on the rise, APIs are emerging to expose web services.
REST is a logical choice for building APIs that allow users to connect
and interact with cloud services.
REST vs SOAP Web Services
REST Web Services:
• RESTful web services are stateless.
• For most servers, RESTful web services provide a good caching infrastructure over an
HTTP GET method. This can improve the performance if the information the service
returns is not altered frequently and is not dynamic.
• Service producers and consumers must understand the context and content being
passed along as there is no standard set of rules to describe the REST web services
interface.
• REST is useful for restricted-profile devices, such as mobile, for which the overhead of
additional parameters are less. REST services are easy to integrate with existing
websites and are exposed with XML so the HTML pages can consume the same with
ease. There is little need to refactor the existing site architecture. As such, developers
are more productive because they don't need to rewrite everything from scratch;
instead, they just need to add on the existing functionality.
• A REST-based implementation is simple compared to SOAP.
• REST does not enforce any message format such as XML or JSON. Whereas, SOAP is
XML based messaging protocol.
REST vs SOAP Web Services
• The Web Services Description Language (WSDL) describes a common set
of rules to define the messages, bindings, operations and location of the
service. WSDL is akin to a contract to define the interface that the
service offers.
• SOAP requires less plumbing code than REST services design (e.g.,
transactions, security, coordination, addressing and trust). Most real-
world applications are not simple and support complex operations,
which require conversational state and contextual information to be
maintained. With the SOAP approach, developers don't need to write
plumbing code into the application layer.
• SOAP web services, such as JAX-WS, are useful for asynchronous
processing and invocation.
• SOAP supports several protocols and technologies, including WSDL,
XSDs and WS-Addressing.
Web Services Advantages
• Service Reuse
• Exposing Business Functionality on the network
• Interoperability amongst applications
•A Standardized Protocol which everybody
understands
• Reduction in cost of communication

You might also like