Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

API Introduction (1)

Uploaded by

Subash Pandey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

API Introduction (1)

Uploaded by

Subash Pandey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Software APIs

INTRODUCTION
by Subash Pandey
@pandeysubash404

IT CLUB of OXFORD COLLEGE


SOFTWARE API
Software APIs are a powerful tool that can
be used to simplify software development
and improve interoperability.
They are used in a wide variety of
applications, including web development,
mobile development, and embedded
systems.
Frontend Backend
APIs Key

An API key is a code used to identify and authenticate an


application or user. For example, users can get a Google API key
or YouTube API keys, which act as a unique identifier and
provide a secret token for authentication purposes.

Why Use API Keys ?


API keys are commonly used to control the utilization of the
API’s interface and track how it is being used.

pk_JPkxhc9cGFv35OWu267fsx8R6uZj29GL

Don’t write your API key directly into your program, as


anyone with access to your source files can see your key.
USE of SOFTWARE APIs?

APIs are used in all sorts of apps, from small projects like school
projects to large-scale global services like Google Maps or
Facebook.
For example, Twitter's famous Tweet button is an API
service that executable code can call and send out a tweet on
behalf of the user (although this has changed in recent versions
with most functionality being part of the page).

Other some example of a software API:

Google Maps API: It allows developers to integrate Google


Maps functionality into their own applications.
OpenWeatherMap API: It allows developers to get weather
data from OpenWeatherMap.
How to use an API ?

To use an API, you will need to:

Find an API that meets your needs.

Understand the API's documentation.

Send requests to the API.

Parse responses of the API's.


In which language should my API be written?

There are no rules for creating an API key. It


depends on your needs, but some common
choices include:

PHP

Java

Ruby

Net
TYPES OF SOFTWARE API
There are many different types of APIs, but some
of the most common include

REST APIs: Based on the Representational State


Transfer architectural style.
SOAP APIs: Based on the Simple Object Access
Protocol.
GraphQL APIs: Are a newer type of API that are
designed to be more flexible and expressive than
REST APIs.
REST API
REST APIs are a type of API that uses the HTTP
protocol to communicate between clients and
servers.
REST APIs are based on the Representational State
Transfer (REST) architectural style, which defines a
set of constraints that must be followed in order to
create a RESTful API.
XML Json

{
<iphone7>
“manufacturer”: “ “apple”,
<manufacturer>Apple</manufacturer>
“os”: “ios 10.0.01”,
<os>ios 10.0.1</os>
“dimensions”: {
<dimensions>
“length”: “138.3”,
<length>138.3</length>
“width”: “67.1” ,
<width>67.1</width>
“heights”: “7.1”
<heights>7.1</heights>
}
</dimensions>
}
</iphone7>
HTTP Response Status Codes
Informational responses (100–199)

Successful responses (200–299)

200 OK For a successful transaction.


201 Created For creating an entry in the database or updating details.

Redirection messages (300–399)

Client error responses (400–499)

404 Not Found The document at the specified URL does not exist.

Server Error Responses (500-599)


HTTP Response Status Codes
Informational responses (100–199)

Successful responses (200–299)

200 OK For a successful transaction.


201 Created
Subash Pandey
For creating an entry in the database or updating details.
@pandeysubash404
Redirection messages (300–399)

Client error responses (400–499)

404 Not Found The document at the specified URL does not exist.

Server Error Responses (500-599)


Main constraints of REST are :

Resource identification: Resources are identified by


URIs.
Resource manipulation: Resources are manipulated
using HTTP methods.
Uniform interface: The same interface is used for all
resources.
Stateless: Clients and servers should not maintain state
between requests.
Cacheability: Resources should be cacheable, if possible.
Resources Identification
In REST APIs, resources are identified by URIs (Uniform Resource Identifiers). A URI is a
string of characters that identifies a resource on the internet. For example, the URI for
the homepage of the Oxford College website is https://www.oxford.com.np/.
It is important in REST APIs because it allows clients to interact with
resources in a consistent way. For example, if a client wants to get the list of all
teachers in a REST API, it would send a GET request to the URI that identifies the list of
teachers.

Here are some examples of resource identification in REST APIs:

The URI for the list of all teachers in a REST API might be /teachers.
The URI for a specific teacher in a REST API might be /teachers/{teacherId}.
The URI for creating a new teacher in a REST API might be /teacher.
Resource Manipulations
Resource manipulations in REST APIs are performed using HTTP methods. The
following HTTP methods are used to manipulate resources in REST APIs:

GET: The GET method is used to retrieve a resource.


POST: The POST method is used to create a new resource.
PUT: The PUT method is used to update an existing resource.
PATCH: The PATCH method is used to partially update an existing resource.
DELETE: The DELETE method is used to delete a resource.

For example, if a client wants to get the list of all users in a REST API, it would send a GET
request to the URI that identifies the list of users. If a client wants to create a new user in
a REST API, it would send a POST request to the URI that identifies the list of users.
Uniform Interface
Here are some of the ways that the uniform interface constraint is implemented in
REST APIs:

URIs: The same URI is used to access a resource regardless of the client or the
method used to access the resource.
HTTP methods: The same HTTP methods are used to manipulate all resources. For
example, the GET method is used to retrieve all resources, the POST method is used
to create new resources, and the PUT method is used to update existing resources.
Response formats: All resources are returned in the same format. The most
common response format is JSON, but other formats such as XML and YAML are
also supported.
Stateless
This means that each request must contain all of the information that the server
needs to process it. Here are some of the benefits of the stateless constraint in REST
APIs:
Scalability: Stateless APIs are scalable because they do not rely on the server to
store state about the client so that the server can handle more requests without
having to store more data.
Reliability: Because they do not rely on the server to remember the state of the
client. This means that if the server crashes, the client can simply send a new
request and the server will be able to process it.
Consistency: Because they do not rely on the server to remember the state of the
client. This means that the client can be sure that the server will process its requests
in the same way, regardless of the order in which the requests are sent.
REAL LIFE WORKING PROCESS
Here are some examples of REST APIs:
The GitHub API
The Twitter API
The Google Maps API

Here are some of the benefits of using REST APIs:


Easy to understand and use: REST APIs are based on a simple and well-
defined set of principles, which makes them easy to understand and use.
Widely supported: REST APIs are widely supported by most programming
languages and web frameworks.
Efficient: REST APIs are efficient because they use the HTTP protocol, which
is a well-known and well-optimized protocol.
Scalable: REST APIs are scalable because they are stateless and cacheable.
Subash Pandey
@pandeysubash404
IT CLUB of OXFORD COLLEGE

You might also like