HATEOAS: concise description

前端 未结 5 701
情话喂你
情话喂你 2020-12-22 18:01

I am trying to get a clear and concise understanding of HATEOAS, and I am by no means an expert WRT REST. (I think I get it though, thanks to this http://www.looah.com/sourc

5条回答
  •  伪装坚强ぢ
    2020-12-22 18:27

    This article helped me to understand it thoroughly. http://restcookbook.com/Basics/hateoas/

    It is simple and elegant.

    HATEOAS stands for Hypertext As The Engine Of Application State. It means that hypertext should be used to find your way through the API. An example:

    GET /account/12345 HTTP/1.1
    
    HTTP/1.1 200 OK
    
    
        12345
        100.00
        
        
        
        
    
    

    Apart from the fact that we have 100 dollars (US) in our account, we can see 4 options: deposit more money, withdraw money, transfer money to another account, or close our account. The "link"-tags allow us to find out the URLs that are needed for the specified actions. Now, let's suppose we didn't have 100 USD in the bank, but we actually are in the red:

    GET /account/12345 HTTP/1.1
    
    HTTP/1.1 200 OK
    
    
        12345
        -25.00
        
    
    

    Now we are 25 dollars in the red. Do you see that right now we have lost many of our options, and only depositing money is valid? As long as we are in the red, we cannot close our account, nor transfer or withdraw any money from the account. The hypertext is actually telling us what is allowed and what not: HATEOAS

提交回复
热议问题