Web services


Socket Programming

Sockets enable Interprocess Communication on same or different machines using TCP/IP protocol suite provided by the operating system. Together, TCP and IP ensure that messages are routed to their correct destination, get from source to destination reliably in the face of failure. Most of the application-level protocols like FTP, SMTP, and POP3 make use of sockets.

This is a typical structure used in Socket Programming system calls.

struct sockaddr_in {
   short int            sin_family;
   unsigned short int   sin_port;
   struct in_addr       sin_addr;

socket(): − Create a socket bind(): − Bind socket file descriptor to address listen(): − mark socket willingness to accept accept(): read(), write(): − Send and receive data

Ports are a communication abstraction that allow multiple (possibly independent) network communications to happen concurrently upon a machine.

Client Server Model

A form of interprocess communication on same or different machines using OS provided transport layer facilities.

Distributed Application structure where a server shares resources (ex. data, compute, storage) with a requestor.

Request/ Response communication pattern protocol specified in application layer

  • API is abstraction layer to specify content format for accessing service


Contrasting a monolithic design, applications can be decoupled into many different services. Microservices typically provide fine-grained API and use an API gateway. For example, client searching a product page on Amazon is going to request a web page with many different services: product price, inventory, review, search, product info. This type of developement is great for enterprises since teams won’t slow down for others and services can be built and deployed independently.


Representational state transfer (REST) is an architectural style of providing web services for interoperability between computer systems, providing these services, and the internet. An API has constraints to be considered RESTful and as such there exists special properties that result from this.

REST Client: Code or an app that can access REST services.

  • Command line tool like cURL
  • Web browser (safari, explorer, chrome)
  • Application (Postman)

REST API: defines the endpoint (a URL) and methods allowed to access/submit data to the server.

A server is listening on that endpoint for requests.

Anatomy of REST:

Endpoint: The URL where the REST Server is listening.


  • GET: Get resource from the server.
  • POST: Create resource to the server.
  • PATCH or PUT: Update existing resource on the server.
  • DELETE: Delete existing resource from the server.

Headers: The additional details provided for communication between client and server (remember, REST is stateless). Some of the common headers are:

  • Request:
    • host: the IP of client (or from where request originated)
    • accept-language: language understandable by the client
    • user-agent: data about client, operating system and vendor
  • Response:
    • status: the status of request or HTTP code.
    • content-type: type of resource sent by server.
    • set-cookie: sets cookies by server

Data: (also called body or message) contains info you want to send to the server.

For a web service to be considered RESTful, it must abide by a few constrains.

1) Resource Only Logical Endpoints

  • Access specification (HTTP)
  • Uniform Resource Identifier (URI) 2) No dependency. Client should only know URL

3) No state. Server treats every request as new.

4) Caching applied to resources when applicable

5) Layered system: Things are abstracted from client


SDK is provides a set of tools, libraries, relevant documentation, code samples, processes, and or guides that allow developers to create software applications on a specific platform.

  • SDKs usually contain APIs; no APIs contain SDKs.
  • SDKs allow for the creation of applications, as a foundation allows for the creation of a house;
  • APIs allow for the functioning of applications within the SDKs defined parameters, like the phone lines of a house.

C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.

Reverse Proxy

A Reverse Proxy sits in front of an origin server and intercepts requests from clients and submits them on their behalf to an origin server. This ensures that clients never directly communicate with an origin server.

This style offers benefits:

  • A load balancing solution could come in the form of a reverse proxy which distributes requests to a number of origin servers equally. This provides resilience against network congestion.
  • Caching frequently requested resources for faster network performance
  • RSA and Elliptic curve cryptography algorithms can be expensive, so performing this on a reverse proxy frees up resources. HTTPS uses the encryption protocol called Transport Layer Security (TLS), which is a form of asymmetric encryption designed to keep requests and responses secure.

API Gateway

An API gateway acts as a reverse proxy and single-entry point for aggregating the various services, through application programming interface (API) calls, fulfilling them and returning the appropriate result.

Possible functions of an API gateway include authentication, rate limiting, and routing publicly accessible endpoints.

Why use API Gateway?

Different clients consume different data. For example a mobile client typically experiences higher network latency (mobile network speeds are slower than LAN and WiFi) in addition to having a less elaborate user interface, therefore should opt for less api requests for better user experience.

The amount of service instances as well as their host & port can change dynamically.

Microservices are fine grained therefore require many api requests.