Hasura Data and Schema Management APIs

3.2 Hasura Data API + Postman collection

After getting through with Data Modelling of my web application DocFinder.Next task is how to make CRUD(Create, Read, Update and Delete) queries and much more across all your tables using Hasura Data APIs.

How it works?

The data service on Hasura exposes an HTTP/JSON API over a PostgreSQL database. This API is designed to be used by any web client (speaking JSON), especially frontend interfaces like Android and iOS apps, browser based JavaScript apps etc.

The data API provides the following features:

  1. CRUD APIs on PostgreSQL tables with a MongoDB-esque JSON query syntax.
  2. Rich query syntax for making complicated select queries.
  3. Role based access control at row and column level.

Internally, it works by converting a JSON query into an SQL statement, executing the SQL statement on Postgres, and then converting the results back into JSON format and sending it back to the client.

Everything about using Hasura Data APIs can be found at the docs below:

After adding Data to the data models created previously, we could make CRUD queries to our database using the external endpoint which can be found at Data and Schema Management part of the console under the section “Manage”.
In my case, it is https://data.chump90.hasura-app.io/

We will be using Postman to make our API requests, which is a powerful GUI platform to make your API development faster & easier, from building API requests through testing, documentation, and sharing. It is recommended to use the free Postman App for Mac, Windows, Linux or Chrome.

As soon as you create a table, an API is instantly available to access that table. However, not everyone can call that API because then any random user on the internet would have access to all our data. All data APIs in hasura use roles to allow row-level and column level access control.

Head to console > data > Tables > user > modify table and scroll down to the permissions section. This is how we would add permissions for the user role.

REQ_USER_ID: (integer) id of the user making a request

After adding tables to Postgres via the Hasura console, the data service is able to provide API for performing CRUD (Create, Read, Update, Delete) queries across all the defined tables.

Using the External endpoint http://data.c100.hasura.me/ , the API can be used and tested using Postman.

First make some changes in the Header and Body section of the Postman app as shown-

  • In the Body section select raw and JSON(application/JSON)
  • Set the request type to be POST and enter the External Endpoint for making use of Data API.
  • In the Header section add the key- Authorization, with value- Bearer <admin token>

Admin Token is available on the Hasura Console

Now,illustration of some CRUD queries using postman on the table Doctor.

Select Query : used to display the data present in the table

Response of Select Query

Insert Query used to display the data present in the table

Response of Insert Query

Update Query

Response of Update Query

Count Query

Response of Count Query

Delete Query

Response of Delete Query

Video Illustration about Hasura Data APIs :

Coming Up!

In the next blog, I’ll talk about Hasura Auth API + Postman collection for my web application Doc Finder.

)
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