Steps to Update the Langman API
Learn the steps for updating the Langman API.
We'll cover the following...
Run server
First, we need to run it just as we did before, except that we need to
specify the JWT_SECRET_KEY
environment variable.
$ export FLASK_APP=server.app
$ export FLASK_ENV=dev_lite
$ export FLASK_JWT_SECRET_KEY=9876543210blastoff
$ pipenv run flask run --host=0.0.0.0 --port=3000
This terminal will now wait and report on communications to port 3000
.
The POST
method
We need to open a new terminal to play the game. We show the full access token only the first time to show how long it is, but then abbreviate it using …
in the other cases.
$ http POST 0.0.0.0:3000/api/auth username=Bobby password=s3cr3t
HTTP/1.0 200 OK
...
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1Nzk4Mzc2MzcsIm5iZiI6MTU3OTgzNzYzNywianRpIjoiOTQyNTNmZDAtODFjOS00NDMzLWIxYzYtZDg2MTgxZDUyMzQ1IiwiZXhwIjoxNTc5OTI0MDM3LCJpZGVudGl0eSI6Ijc3MWJhM2YwLWI4YmYtMzJkYy04ODhkLTQ3N2E5ODkzNGM5ZCIsImZyZXNoIjpmYWxzZSwidHlwZSI6ImFjY2VzcyIsInVzZXJfY2xhaW1zIjp7ImFjY2VzcyI6InBsYXllciIsIm5hbWUiOiJCb2JieSJ9fQ.l0OEB-liBD1zNazBxhj_ZMMEpnqRNjdQoY6MlPItrhM"
}
$ export JWT=eyJ0eXAiOiJKV1...pnqRNjdQoY6MlPItrhM
With the token stored as an environment variable, it becomes easier to start a game.
$ http POST 0.0.0.0:3000/api/games language="en" "Authorization:Bearer $JWT"
HTTP/1.0 200 OK
...
{
"access_token": "eyJ0eXAiOiJKV1Qi...6wH6LM6XmDKzBpBWrDI",
"game_id": "1ad1e8ca-91da-47d4-8dad-7a72cad0094b",
...