How to insert data into Supabase through APIs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone today we're going to do a quick tutorial on how to connect fast gen with Super Bass more specifically we are interested in Reading data within our super bassdb using API endpoints and sending HTTP requests we also want to make changes to that database by inserting rows um and lastly we're going to connect Super Bass within the fastjet platform to access data through SQL top let's get into it right here we are in the table editor of Super Bass and we are looking at a database of docs we do see their names and their breed and we are interested in accessing that data so we're going to hop to the API Builder and fast gen and we're going to add a route and we're going to do a get request here I'm going to call this Read Super Bass and change this to read SB authentication we're going to turn this into a public endpoint for now so Second Step we're going to use an HTTP request we need two things we need the request URL and we need the authentication to access the data so we hop back to Super Bass and here in the top right you see API and you're going to press that Super Bass is here providing us with some information on how to access the data within that table we're going to select bash I'm going to scroll down or we're interested in this reading roles and we're going to do read specific columns we will read name and breed and this example name and breed are the only two columns available we could just pretend that there would also be age location hair color whatever so this is the request URL I'm going to copy it and paste it over here in fast gen going to call this action read SB it is a get request now we need the authentication for it here on the top right we currently hide the API key but you can select service role and then it's going to provide you with the API key here so I'm gonna copy paste the API key in the first step and I'm going to put it in the header API key and this and we're also going to copy paste the bearer token which I think is actually the same in this example but we're gonna paste it nonetheless save this before we save this at the end here in this request you see select and then some column and other column we're going to delete that oops we're going to delete that and put name and breed yeah let's see if this saved it did we're going to put name and breed as we are interested in those two data points I'm Gonna Save and then at the end we're going to put success save this and now we're ready to deploy the endpoint and we can send the first test request to see if everything worked out so everything's green so the request went through let's have a look at the output of that HTTP request and here we can see all of the breeds and names of the docs in our table right here so this is great we could now do with that data whatever we want we could send it somewhere we could display it in the front end we could try to access single data points maybe just do let's just do that in one example so in here I could say output and then I say steps and this is pretty much the out we are trying to access the output of that HTTP request and we say outputs dot body um dot zero dot breed I'm Gonna Save this and deploy it and if we now send a second request that success should show us the breed of the first dog in this table which is um what steps to read SB outputs body zero breed is showing okay so this is how we are accessing data lots of different things we could do here we can read all rows we can read specific rows and then within fashion we can do different things with these data things so let's hop into the API Builder and let's try to add a dog to this table I'm going to put add route and I'm going to put a post endpoint and we're going to call it insert Super Bass and here we're going to say insert SP an authentication we're also going to turn into public endpoint so we're going to do an HTTP request again now we're pretty much doing the same thing again and we're going to scroll down and what we're interested in is inserting rows and right here we see insert ear row you can also insert many rows but we just want to insert one dog for now so we're going to copy paste the request URL again it's pretty much the same as before insert SP but without the select at the end here it's going to be a pulse request that's important so I'm going to post this then we're going to configure the request by setting our authentication once again copy pasting the API key and copy painting our error token all right and we're going to save the changes and save um what we have to do in this HTTP request is now within the Json content we have to specify on what should be added so we're going to add some Json here and we're going to add a name and the name is going to be whatever we send to this request so we're going to put inputs.body dot name I'm going to say breed and this is inputs.body dot breed like this then we're going to save this and save that we're going to put a success message at the end I'm gonna code success and now we will deploy this endpoint as well so let's hop into the debug mode and try to add a dog or we could say name is um Sophie and breed is Husky and now we're going to send a test request everything's green everything went through this is great let's see status code looks good let's look into our Super Bass and we just saw how Sophie husky was added and once again what we did is we sent a pulse request to Super Bass and in here we say the name is whatever we send to this request and the breed is also what we're going to send it to and we send it through the debug mode but you could build a front end and whenever a user is submitting their Dock and their breed could be sent to this request and you added them to the database right here so this is one way of accessing and changing data within your super based database there is a second way these are not mutually exclusive by the way I'm going to hop into a different projects for that I'm going to go to puzzles SV and what we're going to do now is that we really connect the database of Super Bass here so we can utilize the DB query action in this in this project that we just used for utilizing the HTTP request we have our own database so this is not connected to superbase directly so if we would build an API yeah and we would utilize the the bigquery action we couldn't write SQL to make changes to this so this is what we're going to do now in our third example where we will hop to project settings and then we go to external database and now we really want to connect Superbass to the first gen project um so we're gonna hop back to Super Bass because we need the credentials and we will go to Project settings and then we go to database and right here connection info it will already provide us with everything that we need we will copy um what did we just copy we copied the host so horses right this database name is postgres um users also postgres and this is the port is this username is stat and password I'm just gonna generate a new one hit this generate new password gonna copy it I'm gonna enter it right here now I will hit save it failed to connect interesting so let's do some live debugging together reset password okay oh I had to update the password first okay so now it should work if I try it again wonderful perfect so save successfully so now Super Bass is connected to our first gen project we are not able currently to display the Super Bass database here so if you try to press it it will tell you cannot view table but we can make changes to them we can get the data out of it so let's build another API and we're gonna call it um create and we're gonna call it insert Super Bass two now and here we're gonna say insert SP2 gonna turn to public route save it and now we are going to use the dbquery action and not the HTTP request and in here we can now write SQL to also insert a dock and we're just going to test that I'm going to call it insert doc and now we can configure the query and we will say insert into puzzles this is the name of our database right here puzzles so insert into puzzles and we're going to change name and read or we're going to add name and read and the values um are going to be whatever we send to this request now it's going to be inputs.body dot name and it will be inputs.body dot breed okay so let's save the changes save this I'm going to put a success message at the end again now we're going to deploy the endpoint so now we will through the debug mode once again send a test request and now we need a name let's call it Sarah oops we're going to say name and it's going to call it's going to be called Sarah and Sarah is what is a good breed Rottweiler very nice to Hawks Rottweiler okay let's send this test request and let's see what happens so when through went through um one way to find out is to go to puzzles right here and as we can see Sarah was now added to the database those are the two ways of interacting with a supervised database in summary you can build API endpoints using the HTTP request action or you connect your Super Bass database to the first gen project in order to be able to utilize queries both ways are totally functional depending on what you want to do one might be more comfortable than the other but yeah I hope this is helpful Super Bass is an amazing product and an amazing team I think first gen and Super Bass have lots of synergies and yeah if you have any questions reach out and let us know and see in the next video bye
Info
Channel: Fastgen
Views: 3,506
Rating: undefined out of 5
Keywords: API, Supabase, Fastgen, Database, Lowcode
Id: ZPlo59m4tCA
Channel Id: undefined
Length: 13min 22sec (802 seconds)
Published: Tue Jul 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.