Visual Studio Project To cURL A REST Endpoint in C++

Published a new Visual Studio project for running rest operations against an endpoint using C++ or Visual C++. That’s available at

Note: When you compile the project, you will need to add the dependencies so check what’s being imported before doing so.

Obtain a bearer token using curl

In the following, we set a variable called BearerToken using a simple curl to the contents of a bearer token. We do so by running a curl with data in the header for “userid” although sometimes we see this as just “user” or “username” and then a password. This hits an endpoint called authenticationendpoint although sometimes we see that called “auth” or “authenticate” – in this specific case we’re pulling the bearer token out of “id” and it’s nested in there with a name of “token”:
BearerToken=$(curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' --data '{"userid”:”{userid}”,”password":"{password}"}' | sed -E 's/\},\s*\{/\},\n\{/g' File | grep  ‘”id” : “token”’)
Once we have that token we can then pass it into another API via the Authorization header when connecting. In this example we’ll just pass the BearerToken we just captured as such, to an endpoint called EndpointName to
curl -H 'Accept: application/json' -H "Authorization: Bearer ${BearerToken}”