HTTP files now support request variables. That is where you can send a request and then use data from the response, or request, in future requests.
When working with HTTP files, a common scenario is calling an endpoint, taking a value from the response, and sending in a subsequent request. For example, you may call an endpoint to authenticate a user and then on later calls you can pass the token that was returned from the login endpoint. Prior to this release this was not possible in Visual Studio. In the snippet below you can see an example of how this works in an HTTP file.
# @name login
POST {{TodoApi_HostAddress}}/users/token
Content-Type: application/json
{
"username": "{{myusername}}",
"password": "{{mypassword}}"
}
###
GET {{TodoApi_HostAddress}}/todos
Authorization: Bearer {{login.response.body.$.token}}
###
Nenhum comentário :
Postar um comentário