DEV Community

Sumit Roy
Sumit Roy

Posted on • Updated on

Postman, a major tool for developers

How HasuraDB works

Hasura provides API for both data queries and auth queries. HasuraDB is implemented in postgres where we can query RDBMS in json. This saves a lot of backend development time without compromising the security. Thus to test these endpoints we need queries in JSON.

for e.g a select query in sql

SELECT code_text FROM code WHERE private=false;

This is a query for selecting all the codes from a table containing code snippet for my app snipcode which are not private. This will be queried in json like this

{
    "type": "select",
    "args": {
        "table": "code",
        "columns":["code_text"],
        "where": {"private":"false"}
    }
}

Postman at his work

Here comes the role of postman a great tool for testing API endpoints. For my app, I have to test endpoints for both data and authentication. Let's do the above query in postman

postman

This is the above query in postman. There is a dropdown for selecting the method (GET, POST, PUT, etc) and then the URL box for API's URL. The basic setup is setting proper headers and body. In this case, as we know from hasura docs that in headers we have to pass two parameters

 "Authorization": "Bearer xxxxxxxxxxxxxxxx"
 "Content-Type": "application/json"

and call for a POST request.

postman headers

In body, we will select raw input and then the same above query is copied there. In response to this query, we get a json object which can be again will be used on our website. The response is like this

postman response

We can also test the authentication API's via postman But that URL will be different. For data API's the endpoint was http://data..hasura.io/v1/query but for auth API's the endpoint is https://auth..hasura.io. You can find them in the manage section of your project console.

project console

project console

In the same way we have to set headers and in request but we have to pass only one
header this time.

"Content-Type": "application/json"

Suppose we want to register here. Thus the minimum requirement is username and password. So we will pass these in the body.

{
    "username": "postman",
    "password": "nosneaking"
}

and the url will be https://auth..hasura.io/signup.

postman signup

From server we got this as response

{
    "hasura_id": 70,
    "auth_token": "48z0h7lxrh3tr8gxwiqi8e9ngnclwnus",
    "hasura_roles": [
        "user"
    ]
}

postman signup response

We can set cookies using this json response in order to do further data queries for this user. Similarly for login also we can test the endpoint in postman.

Here is the link of my postman queries which will give insight about what kind of queries can be done.

Here is the index of all the post regarding this series of snipcode developemnt

Part I: App Idea
Part II: App prototype
Part III: Local Development
Part IV: G for Git
Part V: Data Modeling
Part VI: Data & Auth APIs
Part VII: Basic Functionalities
Part VIII: App Screen 1
Part IX: App Screen 2
Part X: App Screen 3
Part XI: User Reviews
Part X: Final Submission

Liked my post?

Latest comments (1)

Collapse
 
engineercoding profile image
Wesley Ameling

Oh man, I love postman! I especially use to the tool to test new API's I'm working with. Usually the documentation is quite good, yet seeing it in practice makes the whole process quicker in my opinion.