API Introduction (1)
API Introduction (1)
INTRODUCTION
by Subash Pandey
@pandeysubash404
pk_JPkxhc9cGFv35OWu267fsx8R6uZj29GL
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).
PHP
Java
Ruby
Net
TYPES OF SOFTWARE API
There are many different types of APIs, but some
of the most common include
{
<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)
404 Not Found The document at the specified URL does not exist.
404 Not Found The document at the specified URL does not exist.
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:
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