APIs and MicroServices Flashcards

1
Q

What is an API?

A

Application Programming Interface (API) is a way for one application to connect to another application.

It is a request-response setup where API takes client’s requests to an external system/application and returns the response back from system/application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give an example of API.

A

When we book a flight ticket from the website of the flight company itself, the ticket booking application can directly check the database of bookings and provide a seat.

If we are booking a flight from a third party website which provides us a comparison of prices between different flight companies, the third party client cannot directly connect to the databases of each company. It instead connects to the APIs of those applications, which take the request parameters and lookup their databases. The response provided by APIs is received by the third party client and displayed on screen.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the advantages of APIs?

A
  1. As a client, we have to only “consume” an API, i.e., just send request to it and receive responses from it. We do not have to program it.
  2. APIs are platform independent because even if the client and the API itself are written in two different languages, they communicate with each other via common language such as XML/JSON.
  3. APIs are upgrade safe.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a web service?

A

An API which requires exposure to a network is called web service. An API can also be a simple API which needs no network and only communicates with another application on the same interface without network.

This makes all web services APIs but the vice versa may not be true.

To send data over the internet, it must be in correct format, which could be XML/JSON and must use correct protocol, which could be SOAP/REST.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is XML?

A

Extensible Markup Language (XML) is a type of data sent to/received frommostly SOAP APIs. XML uses tags similar to HTML except that for XML, the tags are extensible, i.e., can be customized.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is JSON?

A

JavaScript Object Notation (JSON) is a type of data sent to/received from mostly REST APIs. JSON uses key value pair
in the format “key”:”value”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is SOAP?

A

Simple Object Access Protocol (SOAP) is a web service protocol that defines the structure of HTTP request/response to connect to a web service. The SOAP request body must use XML for communication.

It must use Web Services Description Language (WSDL) which describes the web service endpoints in XML format. A SOAP request must follow WSDL.

Every SOAP API uses POST method, not because it creates a new resource, but it is used as a mere placeholder as SOAP needs no HTTP method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is REST?

A

REpresentational State Transfer (REST) is an architecture in which server transfers XML/JSON representation of the current state of the resource to the client.

The web services which adhere to this REST style, called RESTful web services, are stateless, meaning no client context is stored on the server.

Unlike SOAP, REST uses HTTP methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the few common web security principles?

A

Authentication- is about validating the identity of client.

Authorization- is about determining the level of client’s access.

Basic Auth- requires username and password which is encoded and sent via the header of HTTP request. If the credentials are correct then the response is sent otherwise 401 Unauthorized Request status is sent.

API Key Authentication- requires APIs to be accessed with a unique key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between APIs and Web Services?

A

APIs and Web Services both facilitate the communication between two applications/services.

Web Services must use network for this communication to take place whereas APIs can work without network.

APIs are lightweight structures whereas Web Services have the overhead of packing and unpacking of data as they use SOAP protocol which is not lightweight.

All Web Services are eventually APIs but not all APIs are Web Services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the two types of web services?

A

SOAP and RESTful

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why are RESTful APIs better than SOAP APIs?

A

SOAP is a communication protocol whereas REST is an architecture style.

RESTful APIs promote loose coupling and allow for greater variety of data formats such as XML, JSON or anything entirely new. This adds a lot of flexibility.

SOAP APIs must use XML, which contains data in essentially string format and needs a layer of metadata on top to describe the data. This makes it heavy.

With REST, We can provide various types of HTTP responses to client but with SOAP, its either 200 OK or 500 Server Error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is HATEOAS?

A

Hypermedia As The Engine Of Application State (HATEOAS) means that a client interacts with the REST API entirely through the responses sent dynamically by the server.

Put even simply, it means that client shouldn’t need any documentation/ out-of-band information to use a REST API.

This might be odd as working with a new API requires going through its documentation to see what endpoints are provided by the API, how requests should be structured and what responses should be expected.

With RESTful APIs, the resources should be discoverable through publication of links.

For e.g. in a banking application, when client clicks a link to view the account balance, the response should also provide links to deposit money, transfer money or close account, without the client having to see documentation.

If the account balance is low, then the links should not contains ways to close account but only to deposit money.

This says that as per requests, the server should dynamically send back new ways of interaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain OAuth.

A

The Open Authorization (OAuth) framework enables a third-party application to obtain limited access to a web service.

In traditional client-server authentication model, the client requests a protected resource on a server by providing its credentials. In order to provide third party applications access to such protected resources, the resource owner had to share the credentials with third party, creating security issues.

OAuth addresses these issues by introducing a layer of authorization. Instead of using the resource owner’s credentials to access protected resources, the client obtains an access token, issued by an authorization server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain the OAuth protocol flow.

A
  1. The client first sends out the Authorization Request to resource owner.
  2. The request is accepted and resource owner sends Authorization Grant to the client which is the representation of resource owner’s authorization.
  3. The client requests an access token by sending the Authorization Grant to authorization server.
  4. Authorization server authenticates the client and validates authorization grant, and if valid, issues Access Token.
  5. The client requests protected resources from resource server and authenticates by providing access token.
  6. The resource server validates access token and if valid, serves the request.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is digest authentication?

A

In basic authentication, the username and password are sent over the network in base64 format, which can be easily translated back to plaintext format, making it highly insecure.

Digest authentication uses a digest scheme, which involves sending the client a random number called NONCE (Number only used ONCE) and a realm (hash) asking it to authenticate.

Under this scheme, the client sends an credentials encrypted by applying hash function to username, password, realm, nonce, HTTP method and the URI requested.

17
Q

Explain webhook.

A

Webhooks are the web services hooked to a particular event such as log in/payment processing/price change of a product/changes in application status etc, where the web service sends response to the client whenever the events occur.

This is reverse of a traditional API, in which client sends request to a web service and web service responds with a response, hence webhooks are also called reverse APIs.

18
Q

Explain microservices.

A

Microservices is an application architectural style in which application is developed as a suite of

  • multiple
  • loosely coupled
  • autonomous

application components aka services (for eg. profile, payment), modeled around business domain, each running in its own process.

It is a modern architecture in contrast with traditional monolithic style, where applications are built as single unit.

19
Q

What are the advantages of microservices?

A
  1. Independent, decoupled Development
  2. Independent Deployment
  3. Fault isolation
  4. Easier testing
  5. Mixed Technology Stack
20
Q

What is Service-Oriented Architecture (SOA)?

A

SOA is an application architectural style where services communicate with each other in one of two ways:

  1. through passing data
  2. through two or more services coordinating an activity
21
Q

How is SOA different from Microservices architecture?

A

SOA relies heavily on Enterprise Service Bus (ESB), which is a communication system bridging the gap between two services when they need to interact with each other. Microservices do not rely on ESB at all.

22
Q

What is cohesion and coupling?

A

The degree to which the elements inside a module belong together is called cohesion.

The strength of the dependencies between components is called coupling.

A good application is said to have high cohesion and low/loose coupling.

23
Q

Explain the architectural style for creating web API?

A
  1. HTTP for client-server communication
  2. XML/JSON as formatting language
  3. Simple URI as the address for service
  4. Stateless communication
24
Q

What is the difference between Ajax and REST?

A

Ajax is a technique of dynamically updating parts of UI without reloading the entire page. REST is a software architecture for client to request data from servers.

In Ajax, requests are sent to server by using XMLHttpRequest objects and response is used by Javascript code to dynamically alter the current view page.

In REST, structured HTTP requests are sent to server and server responds with XML/JSON response encapsulated in HTTP structure.

25
Q

What is JAXB?

A

Formerly Java Architecture for XML Binding and now Jakarta XML Binding, is a framework that allows developers to map Java classes to XML representation and vice versa.

It provides a quick way to marshal (write) Java objects to XML and un-marshal (read) XML into Java objects using Java annotations.

26
Q

What is RPC?

A

Remote Procedure Call (RPC) is a way in which one program calls procedures from another program located in another remote network, without having to understand the network details and lets you exchange data by message passing.

It typically involves generating method stubs on client process, behind which request call to server process takes place. HTTP is sometimes used as underlying protocol for message passing but it is not bound to it.

27
Q

What is the difference between RPC and REST?

A

RPC thinks in terms of verbs, exposing the functionality as function calls that accept parameters and invokes these functions via appropriate HTTP verb, but the HTTP verb has no real meaning to the actual functionality, since different URL is being called every time.

The REST API, in contrast, uses HTTP verbs to represent transactions against resources. All these verbs invoked on same URL provide different functionality.

For a product website,
REST API is finding a particular product by navogating to a webpage and following a set of given links (like product category) and
RPC is directly calling a procedure to get a product by name.

In the first case, changes to API can be made on server directly but in second case, a coordinated deployment to client and server is needed.

For a restaurant service, placing an order will be something like this:

RPC: http://MyRestaurant:8080/Orders/PlaceOrder (POST: {Tacos object})

REST: http://MyRestaurant:8080/Orders/Order?OrderNumber=asdf (POST: {Tacos object})

and retrieving an order will be like this:

RPC: http://MyRestaurant:8080/Orders/GetOrder?OrderNumber=asdf (GET)

REST: http://MyRestaurant:8080/Orders/Order?OrderNumber=asdf (GET)

28
Q

Explain WSDL.

A

Web Service Description Language (WSDL) is an XML notation for describing a web service. It tells us about the functions that a developer can implement or functions that are exposed to clients.

The maojr elements of a WDSL document are:
1. definitions: root element of all WSDLs and defines name and namespace etc of web service.

  1. types: defines data types used by web service.
  2. messages: abstract definition of data being transmitted
29
Q

What is JAX-WS?

A

Java API for XML-based Web Service is an API for creating and consuming SOAP web services. JAX-WS API is built in JDK and hence its usage does not need addition of any extra dependency.

30
Q

What is JAX-RS?

A

Jakarta RESTful Web Services, formerly known as Java API for RESTful Web Services, is a Java specification that provides support in creating web services according to REST architectural pattern.

It uses annotations to simplify the development and deployment of web service clients and endpoints.

31
Q

Explain the structure of HTTP request.

A

HTTP request contains:

  1. Start-line: contains HTTP verb followed by URI and HTTP version

GET category/book/ HTTP/1.1

  1. Headers: describe the Host, user-agent (browser), accepted types of responses (HTML/PDF etc), length
  2. Blank line: indicates that metadata has been sent and now data will be begin
  3. Optional body
32
Q

Explain the structure of HTTP response.

A

HTTP response contains:

  1. Status line: contains HTTP version followed by HTTP status code and status text

HTTP/1.1 403 Forbidden

  1. Headers: describe the Server, type and size of content sent, cookies etc
  2. Blank line: indicates that metadata has been sent and now data will be begin
  3. Optional body