API_Gateway
API_Gateway
Contents
1. What is an API?
2. What is The Amazon API Gateway?
a. The Architecture of Amazon API Gateway
b. API Types Supported by API Gateway
• REST API
• HTTP APIs
• WebSocket APIs
c. Amazon API Gateway Pricing
3. Creating and Using a REST API with Amazon API Gateway
The following illustrations explain the API and its operation well
HTTP protocol is unidirectional where the client sends the request and the server
sends the response (WebSockets is bidirectional communication).
Let’s take an example when a user sends a request to the server this request goes
in the form of HTTP or HTTPS, and after receiving a request server sends the
response to the client, each request is associated with a corresponding response,
and after sending the response the connection gets closed, each HTTP or HTTPS
request establish the new connection to the server every time and after getting
the response the connection gets terminated by itself.
Instagram API permits your applications to retrieve user tags, photos, account,
and much more.
Twitter also provides a REST API which a developer can query to source the latest
tweets, or provide a search query that will return the results in JSON format.
HTTP APIs
The HyperText Transfer Protocol (HTTP) is a method of transferring files such as
text, images, sound, video, and other multimedia files.
This protocol is used to link sites on the internet, often known as the World Wide
Web.
A Web API is a protocol that explains how clients can access resources and which
methods are compatible with your architecture.
These resources can be in the form of JavaScript or HTML elements, information,
or images, among other media kinds.
An HTTP API communicates between two systems using the Hypertext Transfer
Protocol.
HTTP APIs make endpoints available as API gateways, allowing HTTP queries to
connect to a server.
When you schedule a Zoom meeting on your Google calendar, for instance, you
utilize an HTTP API.
Instead of copying and pasting the meeting invitation into a field, the API explains
how Zoom may communicate directly with Google’s servers to embed a Zoom
meeting within the event.
HTTP APIs enable you to create RESTful APIs with lower latency and lower cost
than REST APIs. You can use HTTP APIs to send requests to AWS Lambda functions
or to any publicly routable HTTP endpoint.
For example, you can create an HTTP API that integrates with a Lambda function
on the backend.
When a client calls your API, API Gateway sends the request to the Lambda
function and returns the function’s response to the client.
In API Gateway you can create a WebSocket API as a stateful frontend for an AWS
service (such as Lambda or DynamoDB) or for an HTTP endpoint.
The WebSocket API invokes your backend based on the content of the messages it
receives from client apps.
Unlike a REST API, which receives and responds to requests, a WebSocket API
supports two-way communication between client apps and your backend.
The backend can send callback messages to connected clients.
useEffect(() => {
const ws = new WebSocket(
`wss://your-websocket-server.com`
);
setWebSocket(ws);
...
endpoint.execute-api.com/petstore/pets. (30)
GET /: for read access of the API's root resource that is not
integrated with any backend endpoint. API Gateway responds with
an overview of the PetStore website.
POST /pets: for write access to the API's /pets resource that is
integrated with the backend /petstore/pets resource.
Now, in order to create our first API, sign in to the API Gateway
console
at https://console.aws.amazon.com/apigateway, and
then Under REST API, choose Build, as shown in Figure …
The Resources pane shows the structure of the created API as a tree of nodes. API
methods defined on each resource are edges of the tree. When a resource is
selected, all of its methods are listed in the Methods pane on the right. Displayed
In Deploy API, for Deployment stage, choose “New Stage” because this is the first
deployment of the API. Type a name (e.g., I typed pet-store) in Stage name and,
optionally, type descriptions in Stage description and Deployment description.
In the resulting Stage Editor pane, Invoke URL displays the URL to invoke the API’s
GET / method request, as shown in Figure
n the Stages navigation pane, expand the test stage, select GET on /pets/{petId},
and then copy the Invoke URL value of https://api-id.execute-
api.region.amazonaws.com/test/pets/{petId}. {petId} stands for a path variable, as
shown in Figure
Note: Invoking the API method without any authorization settings is possible
because we set “Authorization type” to “NONE” before. For this, In the GET
method’s Method Execution pane, we can choose Method Request; as AWS_IAM
or Cognito for Authorization.
API GATEWAY SUDHAKARA RAO .C/CLOUD SOLUTIONS