ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Representational state transfer (REST) API
    Modeling/Architecture 2020. 3. 8. 14:39

    1. Overview

    Representational state transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the Internet. RESTful Web services allow the requesting systems to access and manipulate textual representations of Web resources by using a uniform and predefined set of stateless operations. Other kinds of Web services, such as SOAP Web services, expose their own arbitrary sets of operations.

    REST's client-server separation of concerns simplifies component implementation, reduces the complexity of connector semantics, improves the effectiveness of performance tuning, and increases the scalability of pure server components. Layered system constraints allow intermediaries—proxies, gateways, and firewalls—to be introduced at various points in the communication without changing the interfaces between components, thus allowing them to assist in communication translation or improve performance via large-scale, shared caching. REST enables intermediate processing by constraining messages to be self-descriptive: interaction is stateless between requests, standard methods and media types are used to indicate semantics and exchange information, and responses explicitly indicate cacheability.

    2. Architectural constraints

    2.1 Client-server architecture

    The principle behind the client-server constraints is the separation of concerns. Separating the user interface concerns from the data storage concerns improves the portability of the user interfaces across multiple platforms. It also improves scalability by simplifying the server components. Perhaps most significant to the Web is that the separation allows the components to evolve independently, thus supporting the Internet-scale requirement of multiple organizational domains.

    2.2 Statelessness

    The client-server communication is constrained by no client context being stored on the server between requests. Each request from any client contains all the information necessary to service the request, and the session state is held in the client. The session state can be transferred by the server to another service such as a database to maintain a persistent state for a period and allow authentication. The client begins sending requests when it is ready to make the transition to a new state. While one or more requests are outstanding, the client is considered to be in transition. The representation of each application state contains links that can be used the next time the client chooses to initiate a new state-transition.

    • Server contains no client state
    • Each request contains enough context to process the message
      • Self-descriptive messages
    • Any session state is held on the client

    2.3 Cacheability

    As on the World Wide Web, clients and intermediaries can cache responses. Responses must, implicitly or explicitly, define themselves as either cacheable or non-cacheable to prevent clients from providing stale or inappropriate data in response to further requests. Well-managed caching partially or completely eliminates some client-server interactions, further improving scalability and performance.

    2.4 Layered system

    A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way. If a proxy or load balancer is placed between the client and server, it won't affect their communications and there won't be a need to update the client or server code. Intermediary servers can improve system scalability by enabling load balancing and by providing shared caches. Also, security can be added as a layer on top of the web services, and then clearly separate business logic from security logic. Adding security as a separate layer enforces security policies. Finally, it also means that a server can call multiple other servers to generate a response to the client.

    2.5 Code on demand (optional)

    Servers can temporarily extend or customize the functionality of a client by transferring executable code: for example, compiled components such as Java applets, or client-side scripts such as JavaScript.

    2.6 Uniform interface

    The uniform interface constraint is fundamental to the design of any RESTful system. It simplifies and decouples the architecture, which enables each part to evolve independently. The four constraints for this uniform interface are:

    2.6.1 Resource identification in requests

    Individual resources are identified in requests, for example using URIs in RESTful Web services. The resources themselves are conceptually separate from the representations that are returned to the client. For example, the server could send data from its database as HTML, XML, or as JSON—none of which are the server's internal representation.

    2.6.2 Resource manipulation through representations

    When a client holds a representation of a resource, including any metadata attached, it has enough information to modify or delete the resource.

    • How resources get manipulated
    • Part of the resource state
      • Transferred between client and server
    • Typically JSON or XML
    • Example:
      • Resource: person (Todd)
      • Service: contact information (GET)
      • Representation:
        • name, address, phone number
        • JSON or XML format

    2.6.3 Self-descriptive messages

    Each message includes enough information to describe how to process the message. For example, which parser to invoke can be specified by a media type.

    2.6.4 Hypermedia as the engine of application state (HATEOAS)

    Having accessed an initial URI for the REST application—analogous to a human Web user accessing the home page of a website—a REST client should then be able to use server-provided links dynamically to discover all the available actions and resources it needs. As access proceeds, the server responds with text that includes hyperlinks to other actions that are currently available. There is no need for the client to be hard-coded with information regarding the structure or dynamics of the application.

    3. Architectural properties

    3.1 Resource-Based

    • Things vs. actions
    • Nouns vs. verbs
    • Versus SOAP-RPC
    • Identified by URIs
      • Multiple URIs may refer to the same resource
      • Separate from their representations

    3.2 Performance in component interactions

    Performance in component interactions, which can be the dominant factor in user-perceived performance and network efficiency

    3.3 Scalability 

    Scalability allowing the support of large numbers of components and interactions among components.

    3.4 Simplicity of a uniform interface;

    • Defines the interface between client and server
    • Simplifies and decouples the architecture
    • Fundamental to RESTful design
    • For us this means:
      • HTTP verbs (GET, PUT, POST, DELETE)
      • URIs (resource name)
      • HTTP response (status, body)

    3.5 Modifiability of components

    Modifiability of components to meet changing needs (even while the application is running)

    3.6 Visibility

    Visibility of communication between components by service agents

    3.7 Portability of components

    Portability of components by moving program code with the data

    3.8 Reliability in the resistance to failure

    Reliability in the resistance to failure at the system level in the presence of failures within components, connectors, or data

    4. Reference

    gmlwjd9405.github.io/2018/09/21/rest-and-restful.html

    www.restapitutorial.com/lessons/whatisrest.html

    restfulapi.net/

    https://www.youtube.com/watch?v=Q-BpqyOT3a8

    https://en.wikipedia.org/wiki/Representational_state_transfer

    https://www.youtube.com/watch?v=Q-BpqyOT3a8

    https://searchapparchitecture.techtarget.com/definition/RESTful-API

    댓글

Designed by Tistory.