Getting started with the Brew Ha Ha API
The Brew Ha Ha API includes several endpoints that allow client applications to get a list of supported drinks and snacks. The API also returns JSON data and uses traditional HTTP methods to perform actions on data.
In this guide, you’ll authenticate with the API to get a JSON Web Token (JWT) so you can make calls to the API, and then send a test request to the server.
Before you begin
To begin using the API, you need to complete two steps:
- Sign up for the Brew Ha Ha API
- Get a JSON Web Token (JWT) to make API requests
Sign up for the Brew Ha Ha API
Before you can get a JWT, you need to sign up for the Brew Ha Ha API. Your username and password can only consist of letters and numbers.
To sign up for the API:
-
Open a terminal and run the following command:
signup.sh curl -X POST http://127.0.0.1:8000/api/signup/ \-H "Content-Type: application/json" \-d '{"username": "<username>", "password": "<password>"}'You’ll see the following message after you sign up for the API:
signup_success.sh {"message": "Signup successful!"}
Request a JSON Web Token
After you sign up for the API, you need to request a JSON Web Token (JWT) so you can access resources. Without a JWT, you will not be able to make GET
or POST
requests to the Brew Ha Ha API.
To request a JWT:
-
In your terminal, run the following command:
request_jwt.sh curl -X POST http://127.0.0.1:8000/api/tokens/ \-H "Content-Type: application/json" \-d '{"username": "<your_username>", "password": "<your_password>"}'You’ll receive an access token and a refresh token after you send your credentials:
request_jwt_success.sh {"access": "XXXXXXX","refresh": "XXXXXXX"}
Request a refresh token
The access token expires after 15 minutes. You can use the refresh token to request a new access token.
To request a new access token:
-
In your terminal, run the following command:
request_refresh_jwt.sh curl -X POST http://127.0.0.1:8000/api/tokens/refresh/ \-H "Content-Type: application/json" \-d '{"refresh": "XXXXXXX"}'You’ll receive an access token and a refresh token after you send your credentials:
request_refresh_jwt_success.sh {"access": "XXXXXXX","refresh": "XXXXXXX"}
Send a test ping to the server
Now that you have registered with the API and received a JWT, you can send a test ping to the server. This step verifies that you can send calls to the Brew Ha Ha API.
To send a test ping:
-
In your terminal, run the following command:
test_ping.sh curl -H "Authorization: Bearer <your_token>" http://127.0.0.1:8000/api/ping/You’ll receive a successful message indicating that you successfully pinged the server:
test_ping_success.sh {"message": "Test ping successful!"}
Next steps
Congratulations! You’ve successfully registered with the API, received a JWT, and made your first call to the API. Next, consider reading some of the tutorials and guides to explore the Brew Ha Ha API functionality.