Hi. So today I'm going to talk to you about railway functions. Railway functions are the fastest way to deploy your code actually and I'll show you how to do it.
Uh so here we have a railway project, you know, an empty project and all you need to do is just right click and look for the function. Click on it. Now it's going to open up a railway function.
So you have a source code editor here with a boiler plate code. Now the beautiful thing about this function is that it has three templates by default for you. A rest API template, the ability to create a website, you know, with JSX or even the ability to create chrones, right?
All of which comes with a template. So you can decide anyone you want and you can just start from there. Now I can decide to go ahead and deploy this trait.
But I also want to add some functionality and I'm a lazy programmer. So you know what? Let's vibe code.
Uh the railway functions gives you the ability to you know do some prompt engineering here and then click enter to generate a code and then you can deploy. So let's do something. Um what should we do?
So let's create a rest API that returns a list of random dogs uh from the dog. co API. That's one of one of those popular Let's check it out.
dog. ces. One of those very popular dog APIs.
So, let's get back to this. Uh, yeah. So, let there be at least two three API endpoints.
So, now that we have this prompt, uh, you can just do command enter. If you're on Windows, you can do control enter. You can just click this.
So now it's going to go generate a code for us. And yep, here we have it. And that's it.
How many endpoints he has? One, two, three. Uh, okay.
So click on it, deploy. So this is going to go ahead and deploy it. Now the good thing about Railway Functions is that, you know, once you make a change and you save, you can deploy it as many times as possible.
And then, of course, it versions your code. So you can always go back to previous deployment and see the source code from that deployment and then redeploy again. So right now it is is deploying this um and the good thing also about functions is that you can use variables with it.
Railway functions you can also use volumes. You can attach volumes to it. So if I right click then click on attach volume is going to go ahead and attach a volume to this function.
Um you and it uses B. So if you can use B native APIs with this function. Uh so this should deploy quickly and once it's deployed we can now go ahead and click the function and see what the API does.
So now it is deployed. We have a URL. So let's click on it 44.
Well 44 because we don't have like an index API. So let's copy this this route and just do this. Press enter.
Yep. So now we have random API. So if we reload it, it's going to keep giving us random APIs, random images from the dog API.
Uh which other one should we try? Okay, let's try the one for the breed. Copy and paste it here.
Okay, we have a double. Okay, good. Awesome.
So if we reload, you see it keeps changing and that works quickly. I mean, this is so good. We're able to write this in what in less than 2 minutes and deploy and we already have this.
Um so let's do something else. Let's create another function. I want to show you something.
So let's create another function here. Uh this time around we're going to use the website with JSX. Okay.
Uh so here we just going to create like a simple HTML and CSS page and we can easily do that again with prompt engineering. So, let's do something. Let's say create a simple landing uh let's say music player landing page that plays um five songs use um a Spotify use the Spotify team.
All right. So, let's go. Let's wait for it to generate the code for us.
Of course, like it's not going to use valid like songs, right? So here you can see it's already linking to example. com.
So once you you can go ahead and edit that to whatever like you know royaltyfree music you have or you can take it further attach volumes to your function you know make sure you have songs in there and then just reference them. All right so this is done. go ahead and deploy.
So, this is going to deploy and once it deploys, we should be able to see a simple music landing page with some songs. I mean, we've already given it a prompt to use the Spotify. Yeah.
Oh, that was fast. So, let's click on it. Uh, we click on this.
Boom. So, you can see you have this music player. You have a few songs.
Now none of them is going to play obviously but you can go ahead and you know add stuff yourself. So here you can see it you have the source code here. Um so let's do something.
Let's just um let's let's deploy this again. So we're going to add so this is five right? So let's go ahead and add another one.
Add another one. Uh so driver's license. So let's call this um sugar boy.
We can call this um pro prosper song whatever and then save. It's going to stage a change and deploy. Uh so I'm doing this so that you can we can test the like versioning of the code right.
So this is deploying this now. I mean this version of code is different from what we deployed the first time. So if you go to deployment uh this is already successful.
You can see we already have this one that we deployed. Now we can just click on view logs, go to details and you can see the source code from the previous code here. So you can always go ahead and redeploy this if you want this back and go back and see it in in the in the code editor, but we don't need to do that.
So we have a new one. Let's click on the source code. Uh open it up.
Now you can see Sugar Boy prosper song. So simple. So that's all that that that's it about railway functions like so you can add variables to it and when you add variables uh let's go to the one for our API so when you add variables you can always come here and do like bon bon m dot whatever the name of the variable is right and you can always use native b functions like native born api here or you can do bond m.
p import you can do import you can do import dometa m like any of those will work and it will just fetch your railway environment variables. So that's railway functions for you. Now there's some limitations here of course you know this file can only you know contain a max of 96 kiloby and then you can always use it only for like small tasks.
cannot use for like like very big tasks you know u that will require you using a project but you can see how much time railway function has saved us like you can code in the in the in the source code editor we can quickly make changes and deploy again very fast to deploy we can also use we can also v code we can you know tell railway function to go ahead and like do generate code for us so if you want to know more about railway function functions. Um you can go to our documentation and you can just search for functions. Click on it and then here you can see the limitations and you can see every other thing about it.
So that's functions for you and I'll see you in the next lesson.