Life Saver: Hasura Data APIs
Hasura Data APIs
Hasura provides Data APIs that allows us to communicate with the Postgres databases it uses. The queries can be made through simple HTTP requests in JSON format. Hasura provides row level read, write, modify, delete permissions for its databases.
If you would like to know more about Hasura Data APIs then you can check their docs.
We can create multiple roles in Hasura, each of which will come with its own set permissions. I will talk more about roles in the next post.
For each column of every table we can set permissions for each role. We can also restrict access to data that belongs to them, and not others. This can be done with the help of hasura_id, a unique ID assigned to each user.
The queries are made to http://data.<project-name>.hasura.me/v1/query/
for local development and http://data.<project-name>.hasura-app.io/v1/query/
when running on a cloud service provider.
Most of the data queries required for Life Saver are proxied through a custom service running on Hasura, which does multiple requests to the Data Service and returns the result back to the user.
Sample Queries
Updating service provider location:
Making an emergency request:
When an emergency request is made, a request_id is returned which is used to get further information. It also triggers a series of actions like searching for nearby service providers and requesting them.
Cancelling the request:
When a cancel request is sent, the request is cancelled and the service provider is notified.
Postman Collection of all Data API requests can be found here.