zoukankan      html  css  js  c++  java
  • Statelessness Provide credentials with the request. Each request MUST stand alone and should not be affected from previous conversation happened from same client in past.

    The server never relies on information from previous requests. 

    Statelessness

    As per the REST (REpresentational “State” Transfer) architecture, the server does not store any state about the client session on the server side. This restriction is called Statelessness. Each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. Session state is therefore kept entirely on the client. client is responsible for storing and handling all application state related information on client side.

    It also means that client is responsible for sending any state information to server whenever it is needed. There should not be anysession affinity or sticky sessions on server.

    Statelessness means that every HTTP request happens in complete isolation. When the client makes an HTTP request, it includes all information necessary for the server to fulfill that request. The server never relies on information from previous requests. If that information was important, the client would have sent it again in this request.

    To enable clients to access these stateless APIs, its necessary that servers also should include every piece of information that client may need to create state on it’s side.

    For becoming stateless, do not store even authentication/authorization details of client. Provide credentials with the request. Each request MUST stand alone and should not be affected from previous conversation happened from same client in past.

    Application State vs Resource State

    Please do not confuse between application state and resource state. Both are completely different things.

    Application state is server-side data which servers store to identify incoming client requests, their previous interaction details and current context information.

    Resource state is the current state of a resource on server at any point of time – and it has nothing to do with interaction between client and server. It is what you get as response from server as API response. You refer to it as resource representation.

    REST statelessness means being free on application state.

    Advantages of Statelessness

    There are some very noticeable advantages for having REST APIs stateless.

    1. Statelessness helps in scaling the APIs to millions of concurrent users by deploying it to multiple servers. Any server can handle any request because there is no session related dependency.
    2. Being stateless makes REST APIs less complex – by removing all server side state synchronization logic.
    3. A stateless API is also easy to cache as well. A specific software can decide whether or not to cache the result of an HTTP request just by looking at that one request. There’s no nagging uncertainty that state from a previous request might affect the cacheability of this one. It improves the performance of applications.
    4. The server never loses track of “where” each client is in the application, because the client sends all necessary information with each request.

    Reference: Roy T. Fielding on Stateless

  • 相关阅读:
    some things
    关于我的兼职创业历程
    慢牛APP相关截图
    慢牛系列五:用百度语音识别添加自选股
    慢牛系列四:好玩的React Native
    慢牛系列三:React Native实践
    慢牛系列二:前端技术选择
    慢牛系列一:如何抓取股票数据
    会写程序的屌丝是潜力股
    慢牛股票-基于Sencha+Cordova的股票类APP
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9353534.html
Copyright © 2011-2022 走看看