* This is an automated transcript. Please excuse inaccuracies.
Hey everyone, so today in this video we're going to be going over the 8base command line tool and how you can use it to deploy custom server-side logic to a workspace. So, for the rest of this tutorial we're going to be here in the command line and what we're going to start by doing is actually just installing the 8base command line using NPM. So, if we run NPM, install 8base and then plaster in the global flag, so that installs it across our development environment, that will just take a minute to load. Okay. so now loaded. we can see that we got this print out of just some different information on what different commands we have available when using the CLI.
We can always access these or relist these out by running 8base - H or - - help to where it'll print back out which commands are available for use as well as what those commands do. Right now, what we're going to do is, simply create a new 8base project initialize or generate a new server list function and then deploy that to a workspace which then we will trigger from the command line.
The first thing we have to do is authenticate our command line tool which we can do by running 8base login. This is going to open up a browser window which is going to ask us to log in to our 8base account. So, let me just type in my name, email and password. Alright I got it wrong- oh I know what it is, I signed in with Google- cool, and now our command line is successfully authenticated. Now if we go back to it, it's asking us to select which workspace we'd like to be working within. So, I'm just going to go in and click or select the Brokerly app for the sake of this demo. If you want to select a different workspace while working in the command line you always run 8base config; which will allow you to once again go through your workspaces and select which workspace you're currently working within.
Right now, though I'm going to create a new 8base project locally. You can think of a project as all the custom server-side functions that you want to deploy to the server list runtime. So, I'm just going to do 8base in it and well let's call this “Brokerly App”. If you guys went and create that project, we're going to change into that directory. All right and we can see in here it lists out a few packages for us which we're just going to run NPM install and to make sure that all the packages are installed locally.
So, right now we're in a new 8base project in which will be deployed when we deploy to the Brokerly app workspace. What I'm going to do though is generate a custom function for our server-side application. So, I'm going to run a pace generate or G as the alias. Let's make this a resolver function, so for extending the GraphQL API and then let's just call this, “Hello World Resolver”. All right we can run that. So, it creates all the assets as well as some mock files that we will need to have this function run.
So, one thing that's cool that 8base does is it creates the mock for you and so any function that you are using with a generator is ready to go not that that would add any valuable functionality to your project but it's all set up so you can completely understand how the functions work- as well as you can run them locally or invoke them locally, as well as invoke them in the production environment. So, let's just see what that looks like. If we run 8base, invoke local and then give it the name of the function which in this case is Hello World, then we pass it the mock file which we can find right here- let's invoke that or call that cool. And we just saw that we got a result back from our function, which is resolver reacted to bar; foo bar was the data that we passed this service function.
So, what we're going to do now is actually deploy this to the production environment or 8base works place by running 8base deploy. 8base deploy- cool. So, this is going to take a minute but we'll be back once that function is uploaded.
So, now having deployed our functions to our workspace we can trigger them or invoke them from the production environment. What that looks like is simply being able to use the 8base invoke command, giving it the function name, which is Hello World and then somewhere to specify in a mock, we can also use the option of passing at any type of JSON data that we'd like to. So, if we run this command, we can see that take a second and the resolver received our data which is a bar.
So, I hope this gives you a really good idea of how quickly you can create a new project, generate some custom functions and then deploy them to your production workspace. If you would like more information on what types of functions are available, how you can do advanced scripting within them, that will be covered in other videos or you can check out the documentation to get going immediately at Docs.8base.com. Looking forward to seeing you in future videos and take care.
We're excited about helping you achieve amazing results.