API Gateway
API Gateway
What's API :
API stands for Application Programming Interface. It is a set of rules and protocols that allows different software applications to communicate and interact with each other. An API defines how different software
components should interact, specifying the methods, data formats, and protocols that can be used for communication.
APIs can be classified into different types based on their purpose and usage. Some common types include:
• Web APIs: These APIs are designed for communication over the web and are commonly used in web development. Examples include
REST APIs, SOAP APIs, and GraphQL APIs.
• Library/APIs: These are APIs provided by software libraries or frameworks that developers can use to access specific functionalities or
resources within those libraries.
• Operating System APIs: These APIs provide a way for applications to interact with the underlying operating system. They offer access
to system-level services and resources, such as file systems, network connections, and hardware devices.
• Third-Party APIs: These are APIs provided by external organizations or services that allow developers to integrate their applications with
third-party platforms, services, or data sources. Examples include social media APIs, payment gateway APIs, and mapping APIs.
• Social Media APIs: Platforms like Facebook, Twitter, and Instagram provide APIs that allow developers to access their services and
integrate social media functionalities into their applications. These APIs enable developers to post content, retrieve user data, interact
with social graphs, and perform various social media-related tasks.
• Payment Gateway APIs: Companies like PayPal, Stripe, and Braintree offer APIs that enable businesses to integrate online payment
functionalities into their applications or websites. These APIs allow developers to securely process transactions, handle payments, and
manage user accounts.
• Mapping APIs: Services like Google Maps, Mapbox, and OpenStreetMap provide mapping APIs that developers can use to embed
interactive maps, geolocation, and routing functionalities into their applications. These APIs allow developers to display maps, find
directions, geocode addresses, and perform spatial queries.
• Weather APIs: Companies like OpenWeatherMap and Weatherbit provide weather APIs that allow developers to retrieve real-time
weather data and forecasts for specific locations. These APIs enable developers to incorporate weather information into their
applications, such as displaying current conditions, weather forecasts, or creating weather-based notifications.
• Travel APIs: Platforms like Expedia, Skyscanner, and Airbnb offer APIs that enable developers to access their travel and accommodation
services. These APIs allow developers to search for flights, hotels, car rentals, and other travel-related information, as well as book
reservations and retrieve booking details.
• Financial Market APIs: Services like Alpha Vantage, Yahoo Finance, and Bloomberg provide APIs that offer access to financial market
data, including stock quotes, historical prices, market indices, and company information. These APIs enable developers to build financial
applications, algorithmic trading systems, and portfolio management tools.
• Cloud Service APIs: Cloud providers like Amazon Web Services (AWS), Google Cloud Platform (GCP), and Microsoft Azure offer APIs
that allow developers to manage and interact with their cloud services. These APIs enable developers to create and manage virtual
machines, storage resources, databases, and various cloud-based services
So we can say that, we can create, deploy, and manage a RESTful APIs in order to expose backend HTTP endpoints, AWS Lambda functions,
or other AWS services with using Amazon API Gateway.
API Gateway creates RESTful APIs that are HTTP-based. And enable stateless client-server communication and also implement standard
HTTP methods such as GET, POST, PUT, PATCH, and DELETE.
HTTP API
HTTP APIs are the best choice for building APIs that only require API proxy functionality.
REST API
Restful APIs for require API proxy functionality and API management features.
Websocket API
Websocket API for building real-time two-way communication applications, such as chat apps and streaming dashboards.
First use case is Use API Gateway to create HTTP APIs. The main use case of Amazon API Gateway is creating HTTP APIs. HTTP APIs
enable you to create RESTful APIs with lower latency and lower cost than REST APIs.
Second one is Using API Gateway to create REST APIs. An API Gateway REST API is made up of resources and methods. A resource is a
logical entity that an application can access via a resource path.
The last use case is Use API Gateway to create WebSocket APIs. In a WebSocket API, the client and the server can both send messages to
each other at any time.
We will see these Core Concepts directly into AWS Management Console when creating API Gateways. The main core concept is API Gateway.
But also we can API deployment, API endpoint and Proxy integrations are other core concepts that we can configure when create API
Gateways.
• API deployment
A snapshot of your API Gateway API. The deployment must be associated with one or more API stages for clients to use it.
• API endpoint
Hostname for an API deployed to a specific Region in API Gateway.
• Proxy integration
A simplified API Gateway integration configuration.
Usage Plan - A usage plan provides selected API clients with access to one or more deployed APIs. You can use a usage plan to configure throttling and quota limits, which are enforced on individual client API keys
API Developer - Your AWS account that owns an API Gateway deployment (for example, a service provider that also supports programmatic access.) App Developer - An app creator who may or may not have an
AWS account and interacts with the API that you, the API developer, have deployed. App developers are your customers. An app developer is typically identified by an API key.
Resources (could be different projects/business areas) Methods (GET, POST etc.) - Each method along with resources, are deployed to stages, with invoke url for each method under each resource in each stage
Tech Examples :
Create API
Create Get method with below Lambda Code
Test get method using Console
Test get method using Postman
import json
Create API
Create Post method with below Lambda Code
Test Post method using Console
Test Post method using Postman
(Send request as Post request and message as Body)
{
"Country" : "India"
}
import json
def lambda_handler(event, context):
# TODO implement
print(event)
return 'Hello from ' + event['Country']
nameOfCountry=India
nameOfCountry=US
Output : -
"Hello from India"
"Hello from US"
Use this as Lambda function at the time of API gateway creation : versionTest:${stageVariables.lambdaAlias}
And once you click on save it will give below permission updating thing