API Flashcards
w2, 7, 11
what are REST APIs
Representational State Transfer (style)
- uses HTTP, URL/URI, JSON/HTML
REST characteristics (8)
- Client-server model
- Simple uniform(standardised) interface
- language and platform agnostic
- implementation: any language
- deployment: any platform
- invoke: any OS with any language - typically supports HTTP/HTTPS transport
- supports a variety of data formats
- uses “self-describing” data
- layered system
- allow proxies, gateways, firewalls, caches, load balancers, etc. in-between clients and servers - stateless
what does it mean to be stateless
- server processes each API invocation in isolation
- doesn’t maintain states about the client or previous API invocations
- send all necessary context information to the server at the same time when invoking API
- lack standards for security, transactions, etc - need to keep states
What is an intermediary for?
reduces coupling between external clients and the (micro)services
Enterprise Service Bus
collection of (micro)services
API Gateway
a middleware that manages external access to (micro)services in an enterprise solution
- exposes (micro)services as REST APIs ; transforms between different web service standards
- reduces coupling between external clients and microservices
Functionalities and Benefits of API gateway
- helps to decouple the clients and (micro)service providers
- implement many functionalities commonly needed for all the service providers
eg. re-routing of communication data, load balancing, security enforcement, monitoring/logging, caching, aggregation
Disadvantages of API gateway (3)
- an additional single-point of failure
- may cause performance degradation and become a bottleneck since HTTP request/responses going through the gateway may need additional processing
- additional component that needs to be developed, deployed and managed
how does Kong work
An API gateway can route a request from an external client to an internal/upstream (micro)service.
The URLs used by the client and the actual URL of the microservice can be different; the gateway is responsible for the translation (so called routing).
- Expose the Kong container’s 8000 port to the external network for clients to use.
- A service in Kong is set up to store the URL/path (http://book1:5000/book in this case) of the book microservice to be invoked
- actual (micro)service to be invoked is called an upstream service in Kong; it is called an “upstream” service since it is located relatively in the upstream in the call chains from the relatively downstream client;
- A route in Kong is also part of the configurations for a service in Kong; it is set up to map the URL/path from a client request to the upstream service URL;
- Its functionality is like an app.route annotation in a python flask program that maps a URL/path to a python function.
- Each service in Kong can have more than one route.
A service in Kong doesn’t perform actual business functionality; it only does translation of the URLs;
It is just like a wrapper or a storage box that stores an interface to the upstream services.
An upstream service can be a service that performs actual business functionality (e.g., the book microservice in this case), or another external service (e.g., a Google service), or another service inside Kong—in which case, the upstream service is “virtual”, not doing actual business functionality, but just doing another layer of routing.
benefits of using Standard Interfaces (APIs) (3)
- enable more convenient data exchange among different enterprise applications by using commonly used data formats and communication technologies
- language and platform agnostic
- applications become less coupled with each other
- diff apps can be developed and deployed with diff tech
- apps can be made more easily compatible through standardised integration modules, adaptors, connectors, plug-ins, wrappers, etc.
what is a service
a unit that provides one or many functionalities needed to support business requirements and can be used by other applications or services over the network via a standard interface that is independent of programming languages and platforms
- functions in a server are said to be EXPOSED as a service if it provides a standard interface for others to use the functionalities
service VS service interface
service: includes the service interface and the implementation of the functionality (e.g., all the code in the function bodies), via an application programming interface (API).
service interface: the API through which a service can be accessed by other software components.
- A service provider interface can be simply called a server, or just service
- A service consumer interface can be simply called a consumer, client, or user
service oriented architecture
- turn IT systems into services
- develop and maintain enterprise solutions as assemblies of loosely-coupled services
- manage assemblies at various layers of different functionality and/or complexity
- lower layer functionalities can be reused by higher layers
choreography VS orchestrated architectural patterns
choreography:
- no clear central controller of a business process
- microservices can react to any data or event received without knowing who is the sender, and send out data without knowing who is the receiver
- distributed coordination among microservices
orchestrated:
- central controller (eg complex microservice) interacts with other microservices to complete a business process
- centralised coordination among microservices
choreography as an architectural design pattern
implementation of workflow/business process is a composition of services that collaborate in a distributed manner without a single-point of control
- service perform own functions without knowing others; need to know data
- process completed by more than 1 service