From the course: Blockchain Programming in iOS Using Swift

Setting up a server-side Swift project using Vapor

From the course: Blockchain Programming in iOS Using Swift

Setting up a server-side Swift project using Vapor

- [Instructor] Okay so hopefully at this point you have already installed the Vapor 3 framework. So now let's go ahead and create your first Vapor project. So I'm gonna run vapor new and give it some sort of a name for your project, all right? So I'm just gonna say over here you know, blockchain web api. But obviously you can name it anything that you like. So since I already have Vapor installed, it's gonna go ahead and create that project for me. So if I go ahead and look at the directory structure or list all the files you can see a special folder basically that was created by Vapor which is the name of the project that we just did is created. So let's go ahead and jump into the particular folder and you'll see different files and sources folder and public folder and packaged or server sectra inside that particular folder. But one thing you will notice is that you currently don't have any Xcode Project. So if you don't have Xcode how are you even going to open this in Xcode? Well, you can simply use a command vapor xcode which is going to create you the Xcode Project. Now this command depending on if you're downloading dependencies or not, it can take a little bit of time. So, you know, we're gonna come back when this command is actually finished processing. All right, so Vapor Xcode command has completed processing and basically it's saying that do you want to open an Xcode. And I'm gonna say go head and open it now. For you, you should say yes, open an Xcode. I'm gonna say no over here but the reason that I'm saying no is that I have multiple copies of Xcode and it will open up in Xcode 10. I don't want to open it up in Xcode 10, I want to open it up in Xcode 9.4 or 9.3. All right, so what I'm gonna do is I'm gonna explicitly open it up in Xcode 9.3 so right click and open it up in Xcode 9.3. Now if you only do have 9.3 or 9.4 installed, you will say yes and it will open up obviously in whatever the Xcode it will find in your machine. I have multiple copies of Xcode so that's why I have to select that okay I need to open it up explicitly or manually. So here's our project. The first thing you should do is click on this target and make sure that the target is selected as run. All right, that's the first thing. And also, I'm not gonna run this server on my device, I'm gonna run it on the Mac, so let's go ahead and select the Mac. And that's pretty much it. The final thing you need to do is to go ahead and build your project. Now since we are building the project first time, it can take a little bit of time to build this project. All right, so we're gonna come back when the build is completed, and then I'm gonna show you how you can launch your first Web API written in Vapor. All right, so now that the build is finished, go ahead and open up the app folder and go to the routes. Now there is already a bunch of code written in the routes or swift file. I haven't written any of this code, this code comes by default when you create a brand new Vapor project. I think it's good because it gives you a route called hello, meaning if your Vapor server is running you can simply go to that route and it should return hello world. Kind of like an indication that it is working correctly. At this point go ahead click on the run scheme, go to edit scheme and make sure when you click on the run, executable is also set to run. All right, this is very, very important. Close it, and now we can just simply press a play button to start our Vapor server. And you can see on the console that the Vapor server has started on the board localhost:8080, so I can simply copy that board and I can go to a brand new URL and the route that is available to us is hello and when I go to hello you can see that hello world is being displayed. So this kind of proves that at least a Vapor server is now running, right? And in the next lecture we will be introducing that how we can set up our blockchain on the server, all right? So this will be really, really cool so stay tuned for that.

Contents