Story of Data API of hasura and postman

In the previous blog, I talked about hasura API and postman working. That talk was only for authentication part. In this blog, we talk about data API of hasura platform. Before the “/” you must add you working external data API link endpoint. 

Data service exposes query at the endpoint /v1/query. A simple query operation looks like:

POST /v1/query HTTP/1.1

This is for postman request. You can do all operations on data if you have proper permission to do so. For example, you can insert, select, delete and like these all basic.

"type" : "insert",
         "args" : {
           "table"     : "room",
           "objects"   : [
             {
               "id"   : "1",
               "nRooms" : "2",
               "rent" : "1000",
               "room_owner_id" : "3"
             }
           ],
           "returning" : ["id"]
         }

The above code is simple query done through postman to insert the data in my table. For remind purpose, hasura generally takes and gives JSON data structure. So, before implementation, you must train yourself to work with JSON data structure. It will help you to speed up the development of whatever project you are working with hasura.

"type" : "update", 
        "args" : {
          "table"    : "room",
          "$set"      : { "rent" : "2000" },
          "where"     : { "id" : 2 },
          "returning" : ["id"]}

This code is to update the table room. It will set rent to 2000Rs from 1000Rs. Again, this code structure must be maintained. Otherwise, hasura will response with Bad request. You also need to understand some of the hasura errors responses. These are shown below:-

Errors

Status code Description Response structure
200 Success
Request specific
400 Bad request
{
    "path"  : String,
    "error" : String
}
401 Unauthorized
{
    "error" : String
}
500 Internal server error
{
    "error" : String
}

This is going to be the last blog in series of data modeling. For any problem, you must go to documentation to get help.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s