Hasura Data API + Postman Collection


After doing data modelling for my app, I moved to next task in the third week. The task was to learn how to make CRUD queries across all your tables using Hasura Data APIs.




My previous blog post is about data modelling for my app, check it out to understand database schema for my app.

What is an API

Application program interface (API) is a set of routines, protocols, and tools for building software applications. An API specifies how software components should interact and APIs are used when programming graphical user interface (GUI) components.
Hasura provides Data API as well as Auth API on their platform. Before integration of the app with database, first I need to check the APIs and learn how that works. To know more about Hasura Data APIs, refer to this link.
Data service on hasura platform runs as any other service like my app. We need to contact to this data service in order to exchange data to/from the database tables. I used a third party app named Postman, although you can use curl command from Linux terminal, but Postman makes things easy for us because of its GUI interaction. Postman is easy to install and easy to learn. I used this videos to understand the basics API request and response in Postman.


Query using Postman

All query to data service must be in JSON format, and response from the data service is also in JSON, so we need to convert the regular SQL query into JSON format. For example
Regular SQL query: select * from messages order by created;

In Json, it becomes
On sending that data using postman, response from data api is also in json format.



Above is a simple example of retrieving data from a table. We can also make query to insert a new data, delete and update some data.


API Explorer on Hasura Console

Since postman gives trial for only 7 days, but if you are using new console, you can use their API explorer. Search for query and you will get a tempelate.

Insert

This is a simple insertion in a table named user_info, in which there are four columns id, username, name and about. I made a simple query and in that I also put returning option. Response of that query is shown in the right side of the picture.


Select

This is also a simple query to select some data from a table. Here I am selecting all columns from user_info table.





We can not create tables using the query to Auth APIs, because if we need to, we have to put the admin credentials in the application code and it is bad practice. Better to create required tables from the Hasura Console.


What's Next?

My next post is about Hasura Auth API and + Postman collection.

Comments

Popular posts from this blog

User Feedback & Testing of White Board

Idea for an app | First step to internship

Playing with the Octo-Cat