Hasura Internship: Task 3.2

Abhishek Kumar Roy
Jul 23, 2017 · 4 min read

Hello all, this is the seventh blog in Hasura internship’s blogs series. This blog is for Task 3.2. So, after the data modelling is done, I have created the actual database using the Hasura paltform and now it’s time to query the data in the database. Hasura provides API for every table and view so that we can query our database from command line or any platform like Postman. I will talk about what is API, what is postman and how to query our database with postman but first for reference you can look at my data models so that you can get a better understanding of my tables and the data queries.

Data Model:

What is API ?

Here is what google has to say:

API (Application Programming Interface) is a set of functions and procedures that allow the creation of applications which access the features or data of an operating system, application, or other service.

I know I know it’s somewhat difficult to understand what exactly api is from above definition especially for beginners atleast I didn’t get from this definition what it is actually. In simple words, API is something which helps your program to interact with other applications in order to use some features of that application or to send some data or get some information. You see in almost all the websites during signup or login a option to login with “google” or “facebook” and by clicking this, the website uses the google or facebook api to send and api requests to use the login feature and then all the login process is taken care by the api provider. You can understand it more clearly through this short but a nice video.

What is Postman ?

Postman is an app for interacting with the APIs. It has a very easy GUI for making or building the requests and getting the responses. It is available cross-platform i.e. you can install it on windows, linux and Mac as well. You can also add it as a google chrome extension but app is recommended. Alternatives to postman: Insomnia REST Client, Paw, RESTClient etc.

Now it’s time for some data API query through Postman to our tables created on hasura platform. You can refer to this documentation on how to do the data queries in json format to hasura:

Before doing queries, we have to set some things like setting headers and setting the body type etc.

In the above image you can see the api endpoint to query our database, the method is POST and the header “Content-Type” is set to “application/json” and “Authorization” is set to “Bearer <authorization_token>”. Authorization token is the special token which you will get as a response when you do a signup or login api requests which I will talk about in the next blog.

Now to set the body format of our requests go to “Body” tab select “raw” and then choose “JSON(application/json)” from drop down.

Inserting data:

Selecting data:

Updating data:

To see all the data api queries that I made you can look at this postman collection:

So that’s all for now, I will be updating the blog for any changes made during the course of implementing the app. Thanks :)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade