jeudi 8 août 2019

Why is "check username availability" implemented in this way on Twitch?

So I was creating an account on twitch and of course majority of usernames were taken. Suddenly it came to my mind to check how they have implemented "check username availability" (I like to check these things occasionally just to catch some best practices etc.).

First of all they are using POST request, not sure why is POST better than simply using GET (probably because they send some extra data besides username in request payload).

Secondly, they send some additional data in request, and I am not sure what is the purpose of this.

Below are both request and response payload data (requests are sent on key up event).

Request data:

[  
   {  
      "operationName":"UsernameValidator_User",
      "variables":{  
         "username":"user5"
      },
      "extensions":{  
         "persistedQuery":{  
            "version":1,
            "sha256Hash":"fd1085cf8350e309b725cf8ca91cd90cac03909a3edeeedbd0872ac912f3d660"
         }
      }
   }
]

Response data:

[  
   {  
      "data":{  
         "isUsernameAvailable":true
      },
      "extensions":{  
         "durationMilliseconds":19,
         "operationName":"UsernameValidator_User"
      }
   }
]

If someone knows why is this feature implemented in this way, please point out what are the pros and cons of this over sending GET request with username as a request parameter ?




Aucun commentaire:

Enregistrer un commentaire