Web Architecture
This chapter contains a review of the Web Architecture, studied in the Introduction to Internet Programming course.
- Web as an information space where the items of interest are resources;
- Resource identification via Uniform Resource Identifiers (URI);
- URIs are universal, i.e., they can be used to identify resources in any information space;
- Interaction between agents and resources via interaction protocols, such as HTTP (to discover more about the http protocol, check the HTTP Protocol section of the Introduction to Internet Programming course);
- Use of formats to represent state, namely resource state;
- Media-types as identifiers for formats;
- Use of links in representations as a way to relate resources in the information space;
Representation Design
JSON Hypertext Application Language (HAL)
- A media-type for JSON that provides a standardized way to embed hypermedia links in JSON responses;
- Links are represented in the special
_linksproperty of the JSON object:- The key of the
_linksproperty is the relation between the current resource and the linked resource; - The value of the
_linksproperty is an array of link objects, each containing ahrefproperty, which is the URI of the linked resource, atitle, etc;
- The key of the
- Embedded resources represented in the special
_embeddedfield; - No support for representing actions, i.e., non-safe interactions.
Siren
- A hypermedia specification for representing entities;
- Including actions representations in recourse representations:
actionsproperty; - Grouping the non-link resource properties in the
propertiesproperty; - The
linksproperty is used to represent navigational links to other resources; - Media type:
application/vnd.siren+json.
Note - Links vs Actions: The difference between links and actions is that links are navigational and actions are state-changing. Links are used to navigate to other resources, while actions are used to change the state of the current resource. The distinction is important because it allows clients to understand the purpose of a link or action and how it should be handled.
Problem Details for HTTP APIs
- A media-type for JSON that provides a standardized way to represent error responses in JSON responses;
- A problem details object contains the following properties:
type: URI that identifies the problem type;title: short, human-readable summary of the problem type;status: the HTTP status code generated by the origin server for this occurrence of the problem;detail: a human-readable explanation specific to this occurrence of the problem;instance: a URI reference that identifies the specific occurrence of the problem;
- Media type:
application/problem+json.
Orthogonal Specifications
Identification, interaction, and representation are orthogonal concepts, meaning that technologies used for identification, interaction, and representation may evolve independently.
The IANA (Internet Assigned Numbers Authority) manages a set of registries with Web specifications, such as:
HTTP Intermediaries
HTTP enables the use of intermediaries to satisfy requests through a chain of connections. There are three common forms of HTTP “intermediary”: proxy, gateway, and tunnel
The terms upstream and downstream are used to describe directional requirements in relation to the message flow: all messages flow from upstream to downstream. The terms inbound and outbound are used to describe directional requirements in relation to the request route: inbound means “toward the origin server”, whereas outbound means “toward the user agent”.
Proxy
- Message-forwarding agent that is chosen by the client, usually via local configuration rules, to receive requests for some type(s) of absolute URI and attempt to satisfy those requests via translation through the HTTP interface;
- Controls the internet access of the client;
- Audits the client’s internet access;
- Caching of resources.
Gateway (a.k.a. reverse proxy)
- Intermediary that acts as an origin server for the outbound connection but translates received requests and forwards them inbound to another server or servers;
- TLS termination;
- Network isolation;
- Application firewall;
- Caching of resources;
- Load balancing.
Tunnel
- Acts as a blind relay between two connections without changing the messages. Once active, a tunnel is not considered a party to the HTTP communication, though the tunnel might have been initiated by an HTTP request.
NGINX
NGINX is a web server that can also be used as a reverse proxy, load balancer, mail proxy, and HTTP cache.
- Controlling NGINX Processes at Runtime;
nginx -s <SIGNAL>- sends a signal to the master process;- The following signals are supported:
stop- fast shutdown;quit- graceful shutdown;reload- reloading the configuration file;reopen- reopening the log files;
- Configuration Files;
- Load Balancing.