Thursday, June 8, 2017

3.2) Hasura Data API + Postman collection

Hello all !

My app is powered by https://hasura.io/

Ref 3.1) Data Modelling
Postman is a great software ! It was because of it , that I could give/implement any back-end integration of my app. Its impossible to think of developing without it. Its so crucial in understanding the structure of your xhr (XMLHttpRequest). What should be the headers, how many of them in a particular API , what should be the body of each xhr request etc. I used javascript to do all these queries.

Method for all Data API queries : POST
URL for all Data APT queries : https://data.veejay84.hasura-app.io/v1/query

(EXCEPTION both method and : URL for select TEMPLATE are different e.g.
for them Method : GET
URL : https://data.veejay84.hasura-app.io/v1/template/template_name )

Headers are  only one
1) Content-type  , application/json  ONLY  for role  ANONYMOUS (with permissions set)

And two  for the role USER  (with permissions set)
1)  Content-type  , application/json                and
2)  Authorization,  Bearer 
Following are a few examples of data API queries that I made via Postman : 
I.) Body of  a INSERT query to my ask_question table , which stores all the questions
{
  "type":"insert",
  "args":{
    "table":"ask_question",
    "objects":[
    {
    "subject_category":"Science",
    "user_id": 66,
    "user_name":"rayon",
    "your_question":" What is a compound? ",
    "question_title":"what are compounds ?"
     
    }
     ]
  }
}


II.) Body of  a NON- CONDITIONAL SELECT query to ask_question table
 {
  "type":"select",
  "args":{
    "table":"your_answer",
    "columns":["answer_id","user_id","user_name","your_answer","answer2_question_id","answer_date"]
     }
}


III.) Body of a CONDITIONAL  SELECT query to the same table (ask_question)

 {
  "type":"select",
  "args":{
    "table":"ask_question",
    "columns":["question_id","user_id","user_name","subject_category","your_question","question_title"],
    "where":{"user_id":2}
  }
}


IV) Body of a INSERT query to your_answer table

{
  "type":"insert",
  "args": {
   
    "table":"your_answer",
    "objects": [
  {
    "user_id": 66,
    "user_name":"rayon",
    "answer2_question_id":11,
    "your_answer":" read this"
    }
     ]
  }
}



V.) Body of a  SELECT query to the same table (your_answer table) , which stores all the answers

{
  "type":"select",
  "args":{
    "table":"your_answer",
    "columns":["answer_id","user_id","user_name","your_answer","answer2_question_id","answer_date"],
    "where":{"answer2_question_id":2}
  }
}


VI.) Body of the CREATE SELECT TEMPLATE for ask_question table


{
  "type":"create_select_template",
  "args":{
    "name":"questions",
    "select":{
      "table":"ask_question",
    "columns":["subject_category","your_question","question_title","user_name","created_date"]
    }
  }
}
 


SETTING  SELECT, INSERT PERMISSIONS for tables


Following are screen shots of Hasura Data APIs for CURD operations in Postman software


                                                 SELECT QUERY --REQUEST HEADER

                                                 SELECT QUERY REQUEST BODY

                                                    SELECT QUERY RESPONSE BODY

                                                 SELECT QUERY RESPONSE HEADERS


                                                    RUN ANY SQL QUERY


                                                  INSERT REQUEST HEADERS

                                            INSERT REQUEST BODY IN JSON FORMAT

                                            INSERT REQUEST BODY

                                             CREATE SELECT TEMPLATE HEADERS



                                        CREATE SELECT TEMPLATE REQUEST BODY





                                         XHR - CONDITIONAL SELECT
                                         XHR - INSERT QUERY

  XHR - LOGIN






Please leave your comments









1 comment:

  1. Nice explaination Ashutosh! it is to the point...I just feel that u could have posted the screenshots of your code or code snippets to make it look neater.Also mention the language in which u have written the queries!
    Otherwise it is pretty good!

    ReplyDelete

इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया - सुदर्शन फ़ाकिर

 इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया वरना क्या बात थी किस बात ने रोने ना दिया आप कहते थे कि रोने से ना बदलेंगे नसीब उमर भर आप की इस बात...