0% found this document useful (0 votes)
6 views

API

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

API

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

What is API?

Intended Learning Outcomes


At the end of the lesson you should be able to
1. Discuss what is API?
2. Examine the types of APIs.
3. Describe the APIs classification according to the systems for which
they are designed.
4. Create REST APIs using PHP.
What is an API?
• An API is a set of programming codes that enables data transmission
between one software product and another. It also contains the
terms of this data exchange.

Application programming interfaces consist of two components:


•Technical specification describing the data exchange options between solutions with the specification
done in the form of a request for processing and data delivery protocols
•Software interface written to the specification that represents it
What is an API?
• Each API contains and is implemented by function calls – language
statements that request software to perform particular actions and
services. Function calls are phrases composed of verbs and nouns, for
example:
• Start or finish a session
• Get amenities for a single room type
• Restore or retrieve objects from a server.
• Function calls are described in the API documentation.
Types of APIs
Types of APIs
1. Private APIs. These application software interfaces are designed for improving
solutions and services within an organization. In-house developers or contractors
may use these APIs to integrate a company’s IT systems or applications, build new
systems, or customer-facing apps leveraging existing systems. Even if apps are publicly
available, the interface itself remains available only for those working directly with the
API publisher. The private strategy allows a company to fully control API usage.
2. Partner APIs. Partner APIs are openly promoted but shared with business partners
who have signed an agreement with the publisher. The common use case for partner
APIs is software integration between two parties. A company that grants partners with
access to data or capability benefits from extra revenue streams. At the same time, it
can monitor how the exposed digital assets are used, ensure whether third-party
solutions using their APIs provide a decent user experience, and maintain corporate
identity in their apps.
3. Public APIs. Also known as developer-facing or external, these APIs are available for
any third-party developers. A public API program allows for increasing brand
awareness and receiving an additional source of income when properly executed.
Two Types of Public APIs
1. The Open API Definition suggests that all features of such an API are
public and can be used without restrictive terms and conditions. For
instance, it’s possible to build an application that utilizes the API
without explicit approval from the API supplier or mandatory
licensing fees. The definition also states that the API description and
any related documentation must be openly available and that the
API can be freely used to create and test applications.
2. Commercial API users pay subscription fees or use APIs on a pay-as-
you-go basis. A popular approach among publishers is to offer free
trials, so users can evaluate APIs before purchasing subscriptions.
APIs by use cases
APIs can be classified according to the systems for which they are
designed.
• Database APIs. Database APIs enable communication between an
application and a database management system. Developers work
with databases by writing queries to access data, change tables,
etc. The Drupal 7 Database API for example, allows users to write
unified queries for different databases, both proprietary and open
source (Oracle, MongoDB, PostgreSQL, MySQL, CouchDB, and
MSSQL).
• Another example is ORDS database API, which is embedded into
Oracle REST Data Services.
APIs by use cases
• Operating systems APIs. This group of APIs defines how applications
use the resources and services of operating systems. Every OS has its
set of APIs, for instance, Windows API or Linux API (kernel–user space
API and kernel internal API .
• Apple provides API references for macOS and iOS in its developer
documentation. APIs for building applications for Apple’s macOS
desktop operating system is included in the Cocoa set of developer
tools. Those building apps for the iOS mobile operating system use
Cocoa Touch – a modified version of Cocoa.
APIs by use cases
• Remote APIs. Remote APIs define standards of interaction for
applications running on different machines.
• In other words, one software product accesses resources located
outside the device that requests them, which explains the name.
Since two remotely located applications are connected over a
communications network, particularly the internet, most remote APIs
are written based on web standards. Java Database Connectivity
API and Java Remote Method Invocation API are two examples of
remote application programming interfaces.
APIs by use cases
• Web APIs. This API class is the most common. Web APIs provide machine-
readable data and functionality transfer between web-based systems
which represent client-server architecture. These APIs mainly deliver
requests from web applications and responses from servers using
Hypertext Transfer Protocol (HTTP).
• Developers can use web APIs to extend the functionality of their apps or
sites. For instance, the Pinterest API comes with tools for adding users’
Pinterest data like boards or Pins to a website. Google Maps API enables
the addition of a map with an organization’s location.
• Most businesses use more than one API to connect applications and share
information. Some end up needing an API management tool to help them
control, distribute, and analyze different APIs.
API specifications/protocols - RPC
• Remote Procedure Call (RPC)
• Web APIs may adhere to resource exchange principles based on a
Remote Procedure Call. This protocol specifies the interaction
between client-server based applications. One program (client)
requests data or functionality from another program (server), located
in another computer on a network, and the server sends the required
response.
• RPC is also known as a subroutine or function call. One of two ways to
implement a remote procedure call is SOAP.
API specifications/protocols -SOAP
• Service Object Access Protocol (SOAP)
• SOAP is a lightweight protocol for exchanging
structured information in a decentralized, distributed
environment, according to the definition
by Microsoft that developed it.
• this specification contains the syntax rules for request
and response messages sent by web applications. APIs
that comply with the principles of SOAP enable XML
messaging between systems through HTTP or Simple
Mail Transfer Protocol (SMTP) for transferring mail.
• SOAP is mostly used with enterprise web-based
software to ensure high security of transmitted data.
SOAP APIs are preferred among providers of payment
gateways, identity management and CRM solutions, as
well as financial and telecommunication
services. PayPal’s public API is one of the commonly
known SOAP APIs. It’s also frequently used for legacy
system support.
API specifications/protocols - REST
• Representational State Transfer (REST)
• The term REST was introduced by computer scientist Roy Fielding in a dissertation in
2000. Unlike SOAP, which is a protocol, REST is a software architectural style with six
constraints for building applications that work over HTTP, often web services. The
World Wide Web is the most common realization and application of this architecture
style.
• REST is considered a simpler alternative to SOAP, which many developers find difficult
to use because it requires writing a lot of code to complete every task and following
the XML structure for every message sent. REST follows another logic since it makes
data available as resources. Each resource is represented by a unique URL, and one can
request this resource by providing its URL.
• Web APIs that comply with REST architectural constraints are called RESTful APIs.
These APIs use HTTP requests (AKA methods or verbs) to work with resources: GET,
PUT, HEAD, POST, PATCH, CONNECT, TRACE, OPTIONS and DELETE.
API specifications/protocols - REST
• RESTful systems support messaging in different formats, such
as plain text, HTML, YAML, XML, and JSON, while SOAP only
allows XML. The ability to support multiple formats for storing
and exchanging data is one of the reasons REST is a prevailing
choice for building public APIs these days.
• Social media giants and travel companies provide external APIs
to improve their brand visibility even more.
• Twitter has numerous RESTful APIs;
• Expedia has both SOAP and RESTful APIs for its partners

• JavaScript Object Notation (JSON) is a lightweight and easy-to-


parse text format for data exchange. Its syntax is based on a
subset of the Standard ECMA-262 3rd Edition. Each JSON file
contains collections of name/value pairs and ordered lists of
values. Since these are universal data structures, the format
can be used with any programming language.
API specifications/protocols - gRPC
• gRPC is an open-source universal API framework that is also
classified under RPC. Unlike SOAP, gRPC is much newer and
was released publicly in 2015 by Google. With gRPC, the
client application can directly call methods from a server
application located on a different computer as if it was a
local object. This makes it easier to create distributed
services and applications.
• Like SOAP and REST , the transport layer for gRPC is HTTP.
However, similar to RCP, gRPC allows developers to define
any kind of function calls, rather than selecting from
predefined options such as PUT and GET in the case of REST.
• By default, gRPC uses protocol buffers instead of JSON or
XML as the Interface Definition Language (IDL) for serializing
structured data. Here, the developer needs to first define
the structure of the data they want to serialize. Once the
data structures have been specified, they use the protocol
buffer compiler to generate the data access classes in the
programming language of your choice. The data is then
compressed and serialized in binary format at runtime.
API specifications/protocols - GraphQL
• The need for faster feature development, more
efficient data loading due to increased mobile
adoption, and a multitude of clients, made the
developers look for other approaches to software
architecture. GraphQL (Links to an external site.),
initially created by Facebook in 2012 for internal
use, is the new REST with organizations like Shopify,
Yelp, GitHub, Coursera, and The New York
Times using it to build APIs.
• GraphQL is a query language for APIs. It allows the
client to detail the exact data it needs and simplifies
data aggregation from multiple sources, so the
developer can use one API call to request all needed
data. Another special feature of GraphQL is that it
uses a type system to describe data.
• Apps using GraphQL control what data they need to
fetch from a server, which allows them to run fast
even when the mobile connection is slow.
API documentation
• The API documentation is a reference manual with all needed
information about the API, including functions, classes, return types
and arguments.
• Numerous content elements make good documentation, such as:
• a quick start guide
• authentication information
• explanations for every API call (request)
• examples of every request and return with a response description, error messages, etc.
• samples of code for popular programmatic languages like Python, Java, JavaScript, or
PHP;
• tutorials
• SDK examples (if SDKs are available) illustrating how to access the resource, etc.
• Documentation may be static and interactive.
API documentation

You might also like