Test with Insomnia
Last updated
Last updated
Insomnia is a really useful tool to test direct http request before coding them in your app. So you can test your API server directly before coding the client-side code.
Download the Free version of Insomnia
Start Insomnia, You can either create a new collection: Create -> Request,
or import mine Create -> Import from file (you can find the file in Assets/NodeJS folder).
Then click on your new collection to open the list of requests.
From here you can create request to test your API. Let's try to create a new admin user. You can edit an existing request or create a new one.
Change the Body to JSON and put this as body:
Since we are testing locally, the password/email doesn't matter for now. We just use something easy to remember.
Make sure NodeJS is running in your command line window, and click on SEND
If it works, hopefully you should see something like this.
There are no direct function to create the first ADMIN user, so we will go change the permissionLevel in mongo directly. You can open in Mongo Compass, click on your new user and change the permissionLevel to 10
This will allow the admin user to execute more function, and also let it grant permissions to other users if needed.
Now use the auth request to login with the admin user
Body JSON again:
Click on SEND, if it works you should see something like this
This gives you an access_token you will need to execute any requests that require authentication. Copy the access token you got (without the ")
Let's create a new request to read the list of all users
Leave the body empty, instead click on Headers and add one, as header name, write:
And as value paste the access token you got when login in.
Now click on send, it should show the full list of existing users.
Great, now you know how to use Insomnia, you can do the same for all other requests. To know which requests are possible, check the other sections of this doc, or check the .routes.js files inside the NodeJS code.
If you also have a game server, you could create a "server" user with permission level 5. This will allow the user to give rewards and read other users, but won't let it assign permissions or delete users (only an admin can).
To set permission Level of a user through requests, if you already have at least 1 admin user, you can login with the admin user and use
Replace the ID at the end of the URL by the ID of the user you want to target. Use the authorization token of your admin user. And set the body to:
There are only 4 relevant permission levels in this API. By default, for new users the permission Level will be 1, which is what it should be for most users.
To test online request, once you installed your cloud server, you can replace 127.0.0.1 by the IP of your server, or your domain name. If you enabled https, you can also replace http by https in the URL. Other than that everything should work the same.