Rsseco En-Us SG m12 Apisrest
Rsseco En-Us SG m12 Apisrest
1
At the core of the unit
You will learn how to describe the purpose and function of APIs,
including REST.
Most people who use computers are familiar with using a graphical user interface (GUI) to interact with an
application. For example, the AWS Management Console is a GUI that a person can use for interacting with AWS
services.
When computer programs need to communicate with each other, they use APIs. APIs make computer software
accessible to developers through code so that developers can build software programs that interact with other
software programs. APIs work as an intermediary so that applications are able to communicate with each other.
This communication is initiated with an API call. An API call is a message that is delivered to an application as a
request and then returned as a response to the requester. APIs define a standard way of invoking application
functions programmatically.
API example
For example, the weather bureau’s software system contains daily weather data. The weather app on your
phone communicates with this system via APIs and shows you daily weather updates on your phone.
The public APIs of AWS services are another API example. When you use a tool such as the AWS Command Line
Interface (AWS CLI), the tool uses the public APIs exposed by the AWS services to invoke service functions.
What are RESTful APIs?
• A RESTful API is an interface that two computer systems use to
exchange information securely over the internet.
• Is designed for loosely coupled network-based applications
• Communicates over HTTP
• Exposes resources at specific URIs
Some APIs follow the principles of REST. REST APIs communicate over HTTP and follow secure, reliable, and
efficient software communication standards. REST is a popular API design that has largely replaced Simple
Object Access Protocol (SOAP) as the standard for web services. Web-based APIs that adhere to the REST design
principles are said to be RESTful.
RESTful API design principles
Uniform interface
Stateless
Cacheable
Layered system
• Header
• Body (Data)
8
Consider creating a bucket named pets in Amazon Simple Storage Service (Amazon S3). Take a look at the code.
If you recall, the PUT API method primarily is used to update existing resources and can also be use to create a
resource.
• Bucket name: pets
• Endpoints for Amazon S3 with the follow structure: s3.<Region>.amazonaws.com
• Content-Length: Length of the message (without the headers)
• In the example, the content length is 0, and the resource URI is blank (/) because the client does not
need to send anything to the server to create the bucket.
• Date: The date and time of the request
• Authorization: The credential information to authenticate the request to the server
RESTful response example
The following is the response returned by the Amazon S3 createBucket API.
HTTP status
HTTP/1.1 200 OK code
x-amz-id-2: x-amz-id-2
YgIPIfBiKa2bj0KMg95r/0zo3emzU4dzsD4rcKCHQUAdQkf3ShJTOOpXUueF6QKo token
x-amz-request-id: 236A8905248E5A01
Date: Wed, 01 Mar 2006 12:00:00 GMT Date, Location,
Location: /pets Content-Length,
Content-Length: 0 Connection, and
Connection: close Server
Server: AmazonS3
10
Take a moment to examine the response header. The following information provides you with details about the
response header.
{
Response: “Status” : “Accepted”
}
11
Client URL (cURL) is a popular command line tool that you can use to get or send files over HTTP(S). This tool is
useful for testing REST API access. In this example, the user is creating a file on a server.
A request also must provide credentials for authentication in the header of the request. This example does not
include authentication credentials.
12
An HTTP status code is included in REST API responses. It is helpful to know what the codes mean because the
code indicates whether the request was received successfully or if there were errors. Understanding what status
codes indicate—especially the error codes—can be helpful when you troubleshoot REST API requests.
This slide includes the groups of status codes for your reference.
Hundreds of status codes exist, but they are grouped so that the first of the three digits will indicate the general
nature of the status.
**For accessibility: HTTP status codes table. The first column provides status code groups. The second column
describes the status code. The third column provides an example. End description.
Checkpoint questions
1. What is an API used for?
2. Which protocol do RESTful web services use?
3. What does a 200 status code mean in a REST API response?
13
14
Thank you
15