Supabase Edge Functions Quickstart

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] hello everyone welcome to this quick start tutorial for super bass edge functions supervise edge functions are written in typescript run via dino and are deployed all around the world with the superbase cli now let's get started from scratch if you haven't used the super base cli before you can install it with brew install super base slash tab super base now i already have it installed so i will get an error message here if you have it already installed do make sure you run brew upgrade super base just to make sure you have the latest version and you're ready to go and so now that we have all of that what we can do is in our project to create a new function we can simply say superbase functions new hello and so now we have a new hello function and because we're living on the edge let's actually just go ahead and deploy this function so we can say superbase functions deploy hello and we will need to specify a project reference if we haven't already linked our project and so we can just go ahead in our dashboard and we can copy out our project reference here from the url and now let's set this and we're bundling and we are deployed now we can click on the link here to inspect our deployment and so now you can see here this is your function called hello it is active this is the url that you can use to call your function we have created it just now and the region is earth because we're actually deploying it all around the globe on the edge and then also you get some useful command line uh hints here for deployment for deletion and then for secrets to set environment variables for example if you want to interact with third-party apis where you have api secrets then you can set these to be available in the dino environment variables but now let's actually go ahead and have a look at the code in our function and so we can open this in vs code here we see we have a superbase folder functions hello and now this is using dino so we want to install the dino extension for vs code so we can go to the marketplace and install the dino extension from dinoland and once we have that installed we can go and look for the dino initialize workspace configuration we want to enable dino linting and then also let's enable unstable apis and this sets up our settings for dino and so now we can see we have all our things imported our function declarations our types everything is there fabulous and so here we're just um specializing uh here we're just specifying our function handler and then we're calling it and serve and that's all it takes to write a function and then here we have a little code snippet so when we test the function locally we can use this for example of course we can use the superbase client sdks as well so currently in javascript and in the dart flutter client libraries we have the invoke methods available to invoke your functions but you can also just copy out the curl here and then let's go ahead and actually serve up our function locally and to do that we can say superbase functions serve hello and now you will see okay we don't have our superbase project initialized yet for local development so what we need to do is superbase in it to initialize our local project and then if we try to run this again you will see we don't have the docker daemon up and running so actually in order to run things locally we will need um docker so let's start up our docker desktop if you don't have it you can install it great and now our docker desktop is up and running and so we can try this again and you can see okay we will need to run superbase start to start up all our docker containers and you can now see that we have our things running here in docker for our project we're applying kind of initial migrations and now you can see our local superbase stack is up and running on localhost 54321 and what's really cool as well we can we get we get a local version of the superbase studio we can interact with and so we can actually go in here we can interact with tables and with users and all of that as you used to from the cloud hosted dashboard so but now we actually want to now serve up our function locally so let's do that and now we're seeing the function is being served up and we actually also have a watcher process so if we go in here and change this to hello super super cool name and we save that we can see uh here the file has been changed detected we're restarting and we are up and running again and so now we can simply do our um curl command and let's fire that off and we can see request received and here we can see we got a 200 okay and we got a response hello super cool functions so that's it that's how quickly you can get started with superbase functions uh developing and testing locally and then deploying your functions so now that we have tested everything we can just go ahead and redeploy our function superbase functions deploy hello and we will need our project reference that's not the project reference from here and there we go bundling hello and we're deployed again [Music] [Music] you
Info
Channel: Supabase
Views: 21,333
Rating: undefined out of 5
Keywords:
Id: rzglqRdZUQE
Channel Id: undefined
Length: 7min 9sec (429 seconds)
Published: Thu Mar 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.