API Testing with Insomnia - CDCgov/prime-simplereport GitHub Wiki
Intro
This page explains how to make requests to the GraphQL API using Insomnia.
Prerequisites
- Install Insomnia
Setup
Add a new GraphQL request
- Click the + dropdown
- Click "GraphQL Request"
- Update the endpoint to be whatever your backend URL is +
/graphql
- e.g., if running the backend on
http://localhost:8080
, it would behttp://localhost:8080/graphql
- if running the backend on
https://localhost.simplereport.gov/api
, it would behttps://localhost.simplereport.gov/api/graphql
- if trying to make a GraphQL request against production, it would be
https://www.simplereport.gov/api/graphql
- Click the "Header" tab
- Add a new header called
Content-Type
with a corresponding value ofapplication/json
- Add another new header called
Authorization
with a corresponding value ofBearer ${access_token}
(follow these steps to get the${access_token}
value) - Click on the "GraphQL" tab
- Ensure it is a "POST" request
- Paste the following query and ensure you get a 200 response:
query {
whoami {
id
}
}
- You are ready to make requests to the GraphQL API!
access_token
from browser's local storage
Get -
NOTE: You'll need to update the Bearer token periodically, as SimpleReport re-generates access tokens regularly for security purposes.
-
Load the simplereport app in a web browser
- The following will be instructions for a Chrome browser, but other browsers should be similar
-
Open the dev tools for your browser (CMD + shift + I, or right click -> "Inspect")
-
Follow steps 1 OR 2 below
1. via the "Console" tab
- Click the "Console" tab
- Run
localStorage.getItem("access_token")
- Copy the returned value without the beginning and ending quotes
2. via the "Application" tab
- Click the "Application" tab
- Click "Local Storage" and click the URL where the frontend is running
- Get the value of the key called
access_token
Common Issues
- If you see any errors saying it had issues loading the schema or something of that nature, try clicking the small
"schema" with a wrench button
and then click "Refresh Schema"
Tips
Environment Overrides
You may want to create "Environment Overrides" for your collection of requests, so you do not have to update the bearer token on each request manually. To do so, do the following:
- Right-click your collection of requests in the sidebar, and that should open a dropdown
- Click "Environment"
- That should open up a pop-up called "Environment Overrides (JSON Format)"
- Here you can add any variables, for example
{
"bearer": "[YOUR_TOKEN_HERE]"
}
- Now you can use the variable in your requests.