API
APPLICATION
PROGRAMMING
INTERFACE
BY ZUHDI@BERRYBENKA.COM
1
WHAT IS AN API?
In computer programming, an application programming
interface (API) is a set of routines, protocols, and tools for
building software applications. An API expresses a software
component in terms of its operations, inputs, outputs, and
underlying types.
2
WEB APIS
 Web APIs are the defined interfaces through which
interactions happen between an enterprise and
applications that use its assets. Usually in Extensible
Markup Language (XML) or JavaScript Object Notation
(JSON) format.
 API is typically defined as a set of Hypertext Transfer
Protocol (HTTP) request messages.
3
USABILITY OF WEB APIS
Photos can be
shared from sites
like Flickr and
Photobucket to social
network sites like
Facebook and
MySpace.
4
USABILITY OF WEB APIS [2]
Content can be
embedded, e.g.
embedding a
presentation from
SlideShare on a
LinkedIn profile.
5
USABILITY OF WEB APIS [3]
Content can be
dynamically posted.
Sharing live comments
made on Twitter with a
Facebook account, for
example, is enabled
by their APIs. Etc.
6
WEB SERVICES
The two approaches for
interfacing to the web with web
services, namely:
• SOAP (Simple Object
Access Protocol)
• REST (Representational
State Transfer)
7
SOAP VS REST
8
SOAP works on a standard
set of rules based on XML
(eg. HTTP) otherwise REST
supports many format
(JSON, XML,etc) and
doesn’t employ any
additional messaging layer.
SOAP VS REST (USERS)
9
WHAT IS SOAP?
Simple Object Access Protocol (SOAP) is a protocol for
exchange of structured information on a decentralized and
distributed platform using XML (eXtensible Markup
Language).
10
SOAP SIMPLE REQUEST
11
SOAP SIMPLE RESPONSE
12
WHAT IS REST?
Representational State Transfer or REST basically
means that each unique URL is a representation of some
object and supports format like JSON, XML etc.
13
HOW REST WORKS?
14
Using REST, you can get the contents of that object using
an HTTP using some methods like GET, POST, PUT,
DELETE or POST to modify the object.
REST API WITH CURL
 cURL allows you to
connect and communicate
to many different types of
servers with many different
types of protocols.
 cURL currently supports
the http, https, ftp etc.
15
HTTP POST THROUGH CURL
16
HTTP POST THROUGH CURL
[2]
cURL functions:
 curl_init — Initialize a cURL session
 curl_setopt — Set an option for a cURL transfer
• Ch — A cURL handle returned by curl_init().
• Option — The CURLOPT_XXX option to set.
 CURLOPT_URL
 CURLOPT_CUSTOMREQUEST
 CURLOPT_POSTFIELDS
 CURLOPT_RETURNTRANSFER
 CURLOPT_HTTPHEADER
• Value — The value to be set on option.
 curl_exec — Perform a cURL session
 curl_error — Return a string containing the last error for the current
session
 curl_close — Close a cURL session
17
REST CURL SIMPLE REQUEST
18
 URL: http://localhost:8080/api/users/1
 Method: POST
 Content-Type: application/json
REQUEST
REST CURL SIMPLE RESPONSE
19
RESPONSE
SOAP VS REST (2)
20
SOAP VS REST (3)
21
WHY USING SOAP?
22
The main advantages of SOAP web services are:
 Easy to consume – sometimes.
 Rigid – type checking, adheres to a contract (provider and
consumer) have to agree on the exchange format.
 Development tools – using tools
 Can use almost any transport to send the request — SMTP
(Simple Mail Transfer Protocol), JMS (Java Messaging Service).
 Asynchronous processing and invocation—guaranteed level
of reliability and security then ensure this type of operation.
 Stateful operations—provide support to contextual information
and conversational state management. (Security, Transactions,
Coordination, etc).
WHY USING REST?
The main advantages of REST web services are:
1. Lightweight – The requests and responses can be short.
2. Human Readable Results – Flexible & Simple, URIs for Identification
3. Easy to build – No toolkits required
4. Totally stateless operations – Stateless CRUD (Create, Read,
Update, and Delete) operations.
5. Caching situations – Information can be cached because of the totally
stateless operation.
23
URIS FOR IDENTIFICATION
The components of a URI (Uniform Resource Identifier) include:
• Scheme Name—Identifies the protocol (e.g., FTP:, HTTP:,
HTTPS:, IRC:)
• Hierarchical Part—Intended to hold information hierarchical in
nature.
• Query—contains additional identification information that is non-
hierarchical in nature and often separated by a question mark (“?”)
• Fragment—provides direction to a secondary resource within the
primary one identified by the Authority and Path and separated from
the rest by a hash (“#”)
24
SOAP AND REST COMPARISON
25
CONCLUSION
 SOAP requests use POST and require a complex XML while REST
doesn’t.
 SOAP reads cannot be cached on other hand REST could do by a
proxy server.
 REST allows different data formats where SOAP only allows XML.
 REST better performance and scalability.
Continue operations? SOAP it. Stateless operations? REST it.
26
REFERENCES
1. http://www.marutitech.com/soap-vs-rest-a-case-of-
disruptive-innovation/
2. http://carminedimascio.com/2013/09/restful-design-
principles/
3. http://php.net/manual/en/book.curl.php
4. https://en.wikipedia.org/wiki/Application_programming_in
terface
5. http://geeknizer.com/rest-vs-soap-using-http-choosing-
the-right-webservice-protocol/
27
28

What is an API?

  • 1.
  • 2.
    WHAT IS ANAPI? In computer programming, an application programming interface (API) is a set of routines, protocols, and tools for building software applications. An API expresses a software component in terms of its operations, inputs, outputs, and underlying types. 2
  • 3.
    WEB APIS  WebAPIs are the defined interfaces through which interactions happen between an enterprise and applications that use its assets. Usually in Extensible Markup Language (XML) or JavaScript Object Notation (JSON) format.  API is typically defined as a set of Hypertext Transfer Protocol (HTTP) request messages. 3
  • 4.
    USABILITY OF WEBAPIS Photos can be shared from sites like Flickr and Photobucket to social network sites like Facebook and MySpace. 4
  • 5.
    USABILITY OF WEBAPIS [2] Content can be embedded, e.g. embedding a presentation from SlideShare on a LinkedIn profile. 5
  • 6.
    USABILITY OF WEBAPIS [3] Content can be dynamically posted. Sharing live comments made on Twitter with a Facebook account, for example, is enabled by their APIs. Etc. 6
  • 7.
    WEB SERVICES The twoapproaches for interfacing to the web with web services, namely: • SOAP (Simple Object Access Protocol) • REST (Representational State Transfer) 7
  • 8.
    SOAP VS REST 8 SOAPworks on a standard set of rules based on XML (eg. HTTP) otherwise REST supports many format (JSON, XML,etc) and doesn’t employ any additional messaging layer.
  • 9.
    SOAP VS REST(USERS) 9
  • 10.
    WHAT IS SOAP? SimpleObject Access Protocol (SOAP) is a protocol for exchange of structured information on a decentralized and distributed platform using XML (eXtensible Markup Language). 10
  • 11.
  • 12.
  • 13.
    WHAT IS REST? RepresentationalState Transfer or REST basically means that each unique URL is a representation of some object and supports format like JSON, XML etc. 13
  • 14.
    HOW REST WORKS? 14 UsingREST, you can get the contents of that object using an HTTP using some methods like GET, POST, PUT, DELETE or POST to modify the object.
  • 15.
    REST API WITHCURL  cURL allows you to connect and communicate to many different types of servers with many different types of protocols.  cURL currently supports the http, https, ftp etc. 15
  • 16.
  • 17.
    HTTP POST THROUGHCURL [2] cURL functions:  curl_init — Initialize a cURL session  curl_setopt — Set an option for a cURL transfer • Ch — A cURL handle returned by curl_init(). • Option — The CURLOPT_XXX option to set.  CURLOPT_URL  CURLOPT_CUSTOMREQUEST  CURLOPT_POSTFIELDS  CURLOPT_RETURNTRANSFER  CURLOPT_HTTPHEADER • Value — The value to be set on option.  curl_exec — Perform a cURL session  curl_error — Return a string containing the last error for the current session  curl_close — Close a cURL session 17
  • 18.
    REST CURL SIMPLEREQUEST 18  URL: http://localhost:8080/api/users/1  Method: POST  Content-Type: application/json REQUEST
  • 19.
    REST CURL SIMPLERESPONSE 19 RESPONSE
  • 20.
  • 21.
  • 22.
    WHY USING SOAP? 22 Themain advantages of SOAP web services are:  Easy to consume – sometimes.  Rigid – type checking, adheres to a contract (provider and consumer) have to agree on the exchange format.  Development tools – using tools  Can use almost any transport to send the request — SMTP (Simple Mail Transfer Protocol), JMS (Java Messaging Service).  Asynchronous processing and invocation—guaranteed level of reliability and security then ensure this type of operation.  Stateful operations—provide support to contextual information and conversational state management. (Security, Transactions, Coordination, etc).
  • 23.
    WHY USING REST? Themain advantages of REST web services are: 1. Lightweight – The requests and responses can be short. 2. Human Readable Results – Flexible & Simple, URIs for Identification 3. Easy to build – No toolkits required 4. Totally stateless operations – Stateless CRUD (Create, Read, Update, and Delete) operations. 5. Caching situations – Information can be cached because of the totally stateless operation. 23
  • 24.
    URIS FOR IDENTIFICATION Thecomponents of a URI (Uniform Resource Identifier) include: • Scheme Name—Identifies the protocol (e.g., FTP:, HTTP:, HTTPS:, IRC:) • Hierarchical Part—Intended to hold information hierarchical in nature. • Query—contains additional identification information that is non- hierarchical in nature and often separated by a question mark (“?”) • Fragment—provides direction to a secondary resource within the primary one identified by the Authority and Path and separated from the rest by a hash (“#”) 24
  • 25.
    SOAP AND RESTCOMPARISON 25
  • 26.
    CONCLUSION  SOAP requestsuse POST and require a complex XML while REST doesn’t.  SOAP reads cannot be cached on other hand REST could do by a proxy server.  REST allows different data formats where SOAP only allows XML.  REST better performance and scalability. Continue operations? SOAP it. Stateless operations? REST it. 26
  • 27.
    REFERENCES 1. http://www.marutitech.com/soap-vs-rest-a-case-of- disruptive-innovation/ 2. http://carminedimascio.com/2013/09/restful-design- principles/ 3.http://php.net/manual/en/book.curl.php 4. https://en.wikipedia.org/wiki/Application_programming_in terface 5. http://geeknizer.com/rest-vs-soap-using-http-choosing- the-right-webservice-protocol/ 27
  • 28.