Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VS Code REST CLIENT plugin - how do you store variables from data retrieved from a request?

I'm trying to do something simple:

post http://localhost:3001/api/v1/auth HTTP/1.1
Content-Type: application/json

{ 
    "username": "name",
    "password" : "password" 
}

This sends me an authorisation token which I want to use in future calls.

I understand how to update .vscode/settings.json to store environment variables but I want to store the auth token I've just received.

like image 258
Rob Avatar asked Nov 20 '25 03:11

Rob


1 Answers

Ok so you reference a previous API call. Documentation is ... limited. If anyone has thoughts on long-time storage of the token so calls aren't made constantly, that would be great.

### login
# @name postLogin
post http://localhost:3001/api/v1/auth HTTP/1.1
Content-Type: application/json

{ 
    "username": "name",
    "password" : "password" 
}

@token = {{postLogin.response.body.apptoken}}

### Get Profile details
get {{hostname}}/profile
Authorization: Bearer {{token}}
like image 142
Rob Avatar answered Nov 23 '25 01:11

Rob