Repository navigation
Replies: 4 comments 1 reply
|
Yes, you can. Just don't put the $ before accessToken, that is only used for system variables. |
|
As in the example, you need to use |
|
2 topic reply. First - QuestionCan you save a reply (auth token) to somewhere so it can be accessed by multiple .http files? I guess bonus question would be, it would be great to have a file like a .env that I can place into a .gitignore that I can put a user/pass into that the REST client can read to get authentication and that isn't synced to github like the vscode settings file. Second - My example codeTo help others, you can mash together a few examples from the readme page to get a good auth experience, like below. /.vscode/settings.json {
"rest-client.environmentVariables": {
"$shared": {},
"local": {
"apiUrl": "http://localhost:8000/api"
},
"production": {
"apiUrl": "https://production.my.url.example.com/api"
},
"staging": {
"apiUrl": "https://staging.my.url.example.com/api"
},
"demo": {
"apiUrl": "https://demo.my.url.example.com/api"
}
}
}This will then
Notes
my_api.http @contentType = application/json
###
# @prompt email
# @prompt password
# @name login
POST {{apiUrl}}/auth/login
Content-Type: {{contentType}}
{
"email": "{{email}}",
"password": "{{password}}"
}
###
@authToken = {{login.response.headers.Authorization}}
### Test Login by getting dashboard stats
GET {{apiUrl}}/dashboard-stats
Authorization: {{authToken}} |
|
Related update: #1422 This discussion is addressed by the new |
Uh oh!
There was an error while loading. Please reload this page.
For e.g. suppose I login and receive a json response with the accesstoken (at some path, say
$.id). Can I store this into a variable, and, issue the subsequent requests with the same:http://localhost:3000/foo/bar?accessToken={{$accessToken}}?All reactions