I would like to use the got library to make http requests; wit utilizing the Promises correctly.
I have already tried using Promises in my code, and they never work as expected.
Consider the following pseudo-code:
function getToken() {
var response = new Request('https://my-api/get-token')
}
// First, I need to get a token
my_token = getToken();
// Now I can perform actions with it
var folderID = createFolder(my_token, '/root')
renameFolder(my_token, folderID, 'foo_bar')
deleteFolder(my_token, folderID)
As you can see, everything needs to be done synchronously.
- First, I need to get a token from the website
- Then I create something using the token
- Then I work on the created thing
This possibly can't be done using Promises as documented in the got library: https://www.npmjs.com/package/got#usage
I'm at lost on what to do. They don't even provide any examples.
Help me please?