Hasura Data API + Postman collection

Sayali Anant Jawre
3 min readJun 28, 2017

--

Task 3.2) Learn how to make CRUD queries using Hasura Data APIs

Nice to see you all again! Hope you saw our last blog on Data Modelling.If not then head to this link(Here:-link).Now, the next task of week 3 is to understand the CRUD queries. What is this CRUD(sounds something not easy) ??… Simply said, CRUD is an acronym for Create, Read, Update, Delete! (Not that difficult huh :D!)

Hasura Data API???

Hasura comes with a built-in data service that allows clients to communicate with a Postgres database, via HTTP APIs in JSON. The power of Postgres, and the ease of JSON!!

Any client with a HTTP library can use the data service, so most apps can be made completely ‘backend-less’.

So, for making these APIs Postman App is used.(Download the same :P)

Steps for make database calls using Hasura Data API

  1. Log in to hasuractl console and get the External Endpoint from the Data and Schema option on the left side.
External Endpoint

2. Now, open the Postman App and do the following settings as shown :

Postman options

Specify that you want to provide raw data and select Content-Type as JSON(application/json).

3. The next foremost important step is to set Authentication as Bearer <admin token>. You can get the admin token by logging in to the hasuractl console. Under the Project info section you can get the admin token.

Admin token for Authentication

Now, you are ready to use Hasura Data APIs to make database calls.

a. Insert data

Suppose, in our database we want to enter a new data, we use the insert command. In our case, in the “user” table we made an entry for columns “user_id”, “height” and “weight”. The JSON query for the same is as:

Insert query

b. Select data

Now, for retrieving the data for some specific condition, we can use select query. In our case, if we want to retrieve data for the user with weight of 50 kgs, the JSON query will be like:

Selecting users with proper condition

3. Updating data

If we want to update some kind of information about a specific user, we’ll just run the following JSON query:

update query
Result of the update query in the database

4. Deleting data

For deleting some data from the database, we can simply use the delete JSON command. In our example, we can delete a particular user’s record as follows:

Delete query
Result of the Delete query

Thus, we have successfully learned and implemented the JSON queries i.e. CRUD. Now in the next blog, we’ll learn about Hasura Authentication API.Till then Ciao!!!

References :

  1. Documentation for Hasura Data APIs
  2. Examples of Hasura Data APIs

--

--