hello everyone welcome back to my YouTube channel this is going to be the fourth video of our superbase playlist where I will be explaining about the rest end points and all what superbase provide us for quering the database so in the previous three videos I have explained about what is super base how to set up a project with super base and its configuration and what database it uses and how it uses the database how it manage the database so this video is going to be all about rest endpoints so super basically uses a service which
is post CR it is Open Source service which basically sits on top of the postgress database and give us the rest end points from the postgress database directly so uh let me directly go to the superbas dashboard and if you go to the project section this is the project we were continuing with Let me show the tables that we have we have a GTS schema inside there we have two tables characters and user profiles characters table have a row in it so let's just try to get the row via the API so if we go
to the project settings we can go to the API section then we see a rest Endo here it says restful endpoint for quering and managing your database we just uh like this is the rest endpoint which you will be using to query the database and if we go to the docs they say like this is the endpoint which we have then we need to append rest slv1 to uh basically use the rest end points so let's directly jump to our post man and here I will just okay wait let me copy the URL from the
superbase dashboard then just SP rest slv1 SL the name of the table which which we need to access so we have created a table name correctors so a string named correctors then if we just try to hit the API it says no API key found in the request so we need to get the API key and set in it if we just see this section which I've told previously this is our basically key as well as our Public Access token so we just need to copy this go to the postman again and we need to
set the header API key with the token I have already done it so let me move to the postman then if we hit the API we got an error relation public do characters not exist because it tries to uh tries to see the character table inside the public schema but we have created a new schema for that right which is named as GTA so we need to tell superb like hey we need to uh use the GT schema and get the character stable so for that they have given us a header named as accept profile
where which we can uh where which we can tell that we need to query this schema for this table so let's just try to hit the API so we again got a error message the schema must be one of the following which is public so for this thing we need to go to the Super dashboard and if we just scroll down we would see a list of Expos schema from the API we just need to set our GTS schema in this and if I move to postman again if I hit the API what I get
is permission denied for schema GTA so okay so what it is telling is like there's a schema there's a table but the user which is trying to hit the database does not have permission for the schema GTA so all this I will explain in in my RLS video like what is user what is rules and which rule is superas accessing the database with and all but for now the thing which you should know is like permission denied for schema GTA it says like the user which is trying to hit the API does not have the
permission to use the GT schema so to resolve the error we again go to superas dashboard and we move to the SQL editor so on the SQL editor we need to Grant the permission on schema GTA to the authenticated user right so to Grant access to the N enroll I just forget this and let me save it go to the postman then if I just hit the API I get different error this time I get permission inet for table correct s because I need to Grant permission to n enroll for the tables also right so
okay to resolve the error we need to go to the uh super based dashboard then we need to run this query Grant select on gta. correctors to NN what it does it it basically provides the select permission to the N enroll on the table gta. characters now let's move to the postman again let's try to hit the API so okay so now what we got is our actual Row in Json format let me go to the super base and show you what our database actually had if I go to the GT schema then the correctos
table so we actually have a row in which we have name is Franklin Clinton so basically what it does is it it gives us complete data it could also show you some cool features like if you want to let's say we want to only get the name and age of the characters or let's say we want to get only the ID age and name of the characters what we can do is we can just pass a query parameter which is Select equal to EQ dot so everything have a syntax so this is the syntax of
it which I'll be explaining in the consequent videos so this is the syntax of post CR so we want to select the name ID and age and on hitting API then it says it gives us an error okay on uh select we don't need to specify the uh operator and all which was my mistake so uh I got this result then let's say want to filter on anything let's say I want to filter on age like age and if you want to okay so let's select the name and ID of the character we just specify
a essent and then we want age equal to eq. 28 that means age is 28 so it gives us this if I specify something else it won't give me anything it gives me empty array so this is how we simply got a end point from our directly from our database so next what I will be doing is like this is the get route next so if you want to insert the data in the characters table we want to uh like we will be hitting the post API so the URL would be same correctors and then
if I just try to hit the it says empty body which is like let's provide an empty body so it says permission dened for table correctors to my super base then I need to Grant the insert permission to the n r so so let's try to now insert the data I have uh I have the header and this is the header if you want to post the uh data in superway stocks I didn't find it I have to go to the Post gr documentation there I found this if you want to insert the data you
want to use this header if you want to get the data we we would be using this header so let's try to insert I have some body and on inserting I get duplicate key value corrector name because I have already inserted this name let me do it this way and if we just go to the superv dogs see our table go to the schema correct table so we have got this which we inserted just now so if we move to posman and then let's try to hit the get API we would be getting all the
data so this so I will do the delete operation now let's try to delete something in the corrector so for deleting we need to uh Delete on basis of a filter right so we'll be deleting on basis of ID let's go to this and copy the cell content come back to postman just paste it and switch this to delete and try to delete the character so it again give me relation public. correctors does not exist so I guess there is some header issue so which I will just copy the post header I will past it
here I will try to hit the API then I got permission denied so we want to give the delete permission also let me just give that also so for delete it is delete and let's go to the postman again try to hit the API if you hit the API it gives us 2004 no content let us just confirm by going to the super base docs again uh like the super platform again go to correctors so here we see our uh data have been deleted so uh in the same way you can like hit the update
request also let me do that also like I would be hitting the let me just update this let me hit okay I will hit a patch request I just update okay we need to change the ID of character as we have deleted this character I would just copy this character id go to the postman again paste the character id and let's just change his or her name to ABC GP random character on hitting we get permission denied because again we need to give the permission go there go to SQL editor give the update permission uh
also like we don't need to do all this again and again there is ANL statement which Grant all the permission to uh certain roles on a schema so let's go to the post man try to hit the API and it is taking some time which okay so my Wi-Fi just got disconnected okay so I just came back let's add the a once again and go to the super base go to the table editor schema characters now if you'll see we got the name updated so everything is like a piece of cake if if I to
get AP I just got each and every result I hope you like the video and if you do please hit the like button and also subscribe me so that uh it keeps me motivated to create more such content