<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aditya Shinde on Medium]]></title>
        <description><![CDATA[Stories by Aditya Shinde on Medium]]></description>
        <link>https://medium.com/@aditya.422?source=rss-abd6e3231e04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*NCRuF5qnfHwVrNQS2_mKtg.jpeg</url>
            <title>Stories by Aditya Shinde on Medium</title>
            <link>https://medium.com/@aditya.422?source=rss-abd6e3231e04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 22:48:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aditya.422/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[CRUD operations with Vapor]]></title>
            <link>https://medium.com/swlh/crud-operations-with-vapor-8cddc3e622fc?source=rss-abd6e3231e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cddc3e622fc</guid>
            <category><![CDATA[psql]]></category>
            <category><![CDATA[server-side-swift]]></category>
            <category><![CDATA[vapor]]></category>
            <category><![CDATA[fluent]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Aditya Shinde]]></dc:creator>
            <pubDate>Sat, 30 May 2020 13:15:19 GMT</pubDate>
            <atom:updated>2021-05-16T11:59:59.247Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*JX1K26Nervyu3oq8-aTU_Q.jpeg" /></figure><h3>CRUD operations with Vapor 3</h3><p>In the last article, we got started with Vapor, checked how to create a new project, and tried to understand the project structure. In the last article, we had used the SQLite database. You can check the last article<a href="https://medium.com/@aditya.422/getting-started-with-server-side-swift-with-vapor-84497d9b7257"> here</a>.</p><p>In this article, we’ll use the PostgreSQL database, We’ll also learn how to add a new table in the database and then we’ll perform CRUD operations on the table.</p><p>Let’s create a new project named CRUDOperations.</p><h4>Install PostgreSQL</h4><p>If PostgreSQL is not installed on your Mac, please refer to<a href="https://flaviocopes.com/postgres-how-to-install/"> this</a> link for installation.</p><h4>Create Database for Project</h4><p>After installation is finished open the terminal and hit command psql. Your terminal should look like following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYNz1_VV2jMUOM_RRh2XBg.png" /><figcaption>After hitting psql command on terminal</figcaption></figure><p>To create a new database, the command is CREATE DATABASE followed by database name and semicolon (;). I’ll name the database the same as we’ve named project that is ‘crudoperations’. So hit following command in the terminal now.</p><pre>CREATE DATABASE crudoperations;</pre><p>If your terminal looks like following, your database is created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q9F2MUKIOGDkFqb6jjw_Bw.png" /><figcaption>Create database</figcaption></figure><h3>Configure project to use PostgreSQL</h3><h4>1. Update Package.swift</h4><p>When we create a new Vapor project, by default it uses the SQLite database. To use the PostgreSQL database, we have to change the dependencies in Package.swift file.</p><p>Package.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20690eeefa76ce3245873bc12939e611/href">https://medium.com/media/20690eeefa76ce3245873bc12939e611/href</a></iframe><p>Check the code changed under comment 1 &amp; 2</p><ol><li>In dependencies, we changed our fluent ORM from SQLite to PostgreSQL.</li><li>In targets for app target, we changed dependency from FluentSQLite to FluentPostgreSQL.</li></ol><p>Now on terminal run following command</p><pre>vapor xcode</pre><p>This command will install the dependencies we’ve added in the Package.swift file.</p><h4>2. Update configure.swift</h4><p>We have to update code in the configure function of the configure.swift file. I’ve added numbers in the comments in code. Let’s discuss them in detail.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6edc0b1bbe3ed042e5de4e3254ed7f19/href">https://medium.com/media/6edc0b1bbe3ed042e5de4e3254ed7f19/href</a></iframe><ol><li>We’ve decided to use the PostgreSQL database so we’ve to import is ORM FluentPostgreSQL here.</li><li>We have to register the FluentPostgreSQLProvider. So we are replacing FluentSqliteProvider with this one.</li><li>As we are not using SQLite any more, the line where I’ve added 3rd comment, I’ve commented it for reference, you can remove it.</li><li>We have to create PostgreSQLDatabaseConfig where our hostname would be <strong>localhost</strong>, the port would be <strong>5432</strong>, the username would be <strong>your machine user name</strong>, database name would be CRUDOperation which we had created.</li><li>In comment 5 line, we create an object of PostgreSQLDatabase with the help of the config.</li><li>In comment 6 we add our database object in databases.</li><li>As I had mentioned in the last article, we use migrations to add or alter the tables in the database. In comment 7, I am adding a table named <strong>Pet</strong> in the database. At this moment this line with show error because we have not created a model named Pet yet. It would be resolved once we create it.</li></ol><h4>3. Remove unwanted files</h4><p>We won’t be using Todo.swift and TodoController.swift files. We will be creating our model and controller. Remove these two files from the project navigator. Refer following image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*qBF8X6bCyvrK983P0wlOsw.png" /><figcaption>Remove these two files</figcaption></figure><p>Once these files are removed, go to routes.swift file and remove the code written to add routes and call functions from TodoController. You have to remove the code written under the comment</p><blockquote>// Example of configuring a controller</blockquote><h4>4. Create a new model for table Pet</h4><p>Create a new swift file named Pet.swift in the group Models. Once the file is created, write the following code into the file. Now if you run the code, it won’t show any compilation error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72355e025f1f5060aa449dcfb2603dee/href">https://medium.com/media/72355e025f1f5060aa449dcfb2603dee/href</a></iframe><p><strong>Let us understand the code in Pet class step by step</strong></p><ol><li>In the last article, we’ve already discussed that Fluent is ORM provided by Vapor. We are using the PostgreSQL database for this project. That is why we are importing the FluentPostgreSQL module here.</li><li>Whatever tables we’ll need in the project, we’ll be creating those as classes in our code. For table Pet, here I’ve created class Pet. I’ve made this class ‘final’ so that it won’t be inherited. And it shouldn’t because it is representing one of the tables in our database. I’ve confirmed protocol PostgreSQLUUIDMdel, because I want our Pet must have a unique identifier and it should be of type UUID. In case you want id should be of type int, you have to confirm PostgreSQLModel protocol instead.</li><li>Here I am declaring the properties of my class. In other words we are specifying the columns of our table. I’ve declared id as optional because id would be automatically generated whenever new entry would be added to the table. Fluent will take care of that. Then I’ve declared other properties like type, breed, and name.</li><li>Here, I’ve written the constructor for our class. Constructor doesn’t accept anything for id because as I mentioned in step 3, id is optional, and Fluent will generate it automatically for us.</li><li>I’ve confirmed the Parameter protocol with our class. If you want any web service to use Pet as a dynamic parameter in the URL, this will take care of that. We’ll learn more about this in upcoming articles.</li><li>I’ve confirmed the Content protocol with our class here. As I’ve mentioned in the last article, Content is a superset of the Codable protocol we use in iOS coding. Content helps us to convert our models to JSON when we have to return the output of our web services and vice versa.</li><li>I’ve confirmed the Migration protocol here. Migration helps us to alter the table whenever we need it. If we need to add a new column in the table or we want to delete any column from the table, we’ll be writing that code here. We’ll learn how to do this in the future.</li></ol><h4>5. Postico</h4><p>Now run the app ins Xcode and our table is ready. If you want to check the table, you can download Postico. Postico is a PostgreSQL client for Mac. Once you download and open it, you’ll see the following window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gRhcnffN_D-peBdrLe9-uw.png" /><figcaption>Postico</figcaption></figure><p>Click on the edit button. It will ask you to fill some information. It is the same information we have provided in the config.swift file while creating PostgreSQLDatabaseConfig. Check the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iZ9uf2LWupH5BL5JXASEGQ.png" /><figcaption>Database configuration information</figcaption></figure><p>Once you provide all the information like above, click on connect. It will open the database. You’ll see two tables, Fluent and Pet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jfS6ZtvNPRJ5lsXFOeAuNw.png" /><figcaption>Pet table is created.</figcaption></figure><p>Isn’t it easy to create tables with Vapor? If you open the Pet table now, it would be empty.</p><h4>6. PetController</h4><p>Now as our table is created, it is time for us to write web services, which will write and read data from the table. For this create a new swift file in the Controllers group and name it ‘PetController.swift’. We are going to write all the web services in this class which are related to the Pet table.</p><p>Everything is set now. So let the CRUD begin.</p><h3>CRUD</h3><h4>1. Create</h4><p>Write the following code in ‘PetController.swift’.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd4b178fc2b66b345ae653fc876244a1/href">https://medium.com/media/fd4b178fc2b66b345ae653fc876244a1/href</a></iframe><ol><li>We have written this function to add a new Pet in our pet table. The function takes the HTTP request as a parameter and returns an object of Pet class. In other words, it returns the JSON object of Pet. We can see there something written as the Future. Just to elaborate this first we have to understand that Vapor is a completely asynchronous framework. Multiple requests received at the server, performed on a separate thread. That means the function doesn’t need to return the object of Pet immediately. The server might be busy performing some other operation. But this return type ‘Future&lt;Pet&gt;’ specifies that the function ‘createNewPet’ returns Pet object soon.</li><li>We’ll be passing a JSON object which will contain pet data like type, breed, name (everything excluding id, which will be automatically generated), in POST request. In step 2 we decode the JSON to Pet object and flatMap it to get the pet object which we’ve received from the request. A small note, we can decode JSON data received in the HTTP request as Pet object because we’ve confirmed the ‘Content’ protocol with our Pet class. As it is already mentioned above, Content is a superset of the Codable protocol of swift.</li><li>In the flapMap closure, we get the data which we’ve received from the request in Pet model’s object and now with the function ‘save’, we are storing into Pet table as a new record. ‘save(on:_)’ returns the same model which is passed as an argument.</li></ol><h4>Route</h4><p>Now we’ve to add an HTTP method and an URL with which we can call this create pet web service. Add the following code in ‘routes’ function of the router.swift file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7393dbc41601e47be8a0a6d49bc45e32/href">https://medium.com/media/7393dbc41601e47be8a0a6d49bc45e32/href</a></iframe><ol><li>We have created an object of PetController class</li><li>We’ve specified that the router will use the HTTP post method, it’s path component is a pet. That is the end URL for this would be ‘<a href="http://localhost:8080/pet">http:/localhost:8080/pet</a>’ and it has to trigger ‘createNewPet’ function of PetController.</li></ol><p>Now run the project in Xcode and let us test create operation with ‘Postman’.</p><p>In postman paste the above URL in the textbox, select the POST method and in Headers, add Content-Type, ‘application/json’. It should look like following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PJ2is7X4JPjYPV4W0oLGw.png" /><figcaption>Content-type should be application/json</figcaption></figure><p>Then in Body tab add JSON data with your desired values like in the following image, I’ve added name as Tom, the breed is Lab and type is Dog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LoOyGJWU-bGyZcrCw_Pkxg.png" /><figcaption>Pet data</figcaption></figure><p>Once all this is done, click on send button and in response, you should be able to see the same pet data you’ve passed along with id, like the following image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-EqD5bSPyw_JyXFO_YaUQ.png" /><figcaption>Web service response</figcaption></figure><p>You can verify this by checking if the table is having this entry. To check this, open the Pet table in Postico, you should see something like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YvUdG2kZX5DAbA5HJF4NNQ.png" /><figcaption>First pet entry in the table</figcaption></figure><p>Like this, you can add some more pets to the table.</p><h4>2. Read</h4><p>Now we have some data in our database. We’ll try to read that data now. We’ll write a web service that will fetch(read) all the pet records from the pet table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c33a602046de5aaf3933d38d685410ad/href">https://medium.com/media/c33a602046de5aaf3933d38d685410ad/href</a></iframe><ol><li>We’ve written a function named ‘getAllPets’ which accepts HTTP request as a parameter and returns an array of Pet objects with Future.</li><li>We query on the Pet table with request and call function named ‘all’ which returns an array of the model on which we are querying.</li></ol><p><strong>Route</strong></p><p>Add the following lines in the ‘routes’ function of routes.swift file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/496d3d9b6a39b79ad5966e0b8c012eed/href">https://medium.com/media/496d3d9b6a39b79ad5966e0b8c012eed/href</a></iframe><p>We’ll use the HTTP GET method. The path component would be the same as that is a pet. So the final URL won’t change. And we are using ‘getAllPets’ function of PetController.</p><p>Now run the project in Xcode and test the new function in postman. You should be able to see output similar to the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwoZa-Ty4CytsBtM7gxsxg.png" /><figcaption>Get all pets</figcaption></figure><h4>3. Update</h4><p>To perform an update, we’ll use the HTTP PUT method. We need to identify the pet which wish to update with some unique property. In our case id is that property. I’ve a dog in my pet table named ‘Tom’. I want to update its name as ‘Tomas’. For this first add following function into PetController.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7050b089f241d74adb1254497cb87479/href">https://medium.com/media/7050b089f241d74adb1254497cb87479/href</a></iframe><ol><li>We’ve created a function named ‘updatePet’ that accepts HTTP request as a parameter and returns Pet object with updated data.</li><li>In this case, we’ll be appending the ‘id’ of the pet which name we wish to update. We’ll also be passing JSON with updated pet data with the request. That is why when we flatMap in this step, first we get the pet object which id we’ve added in the URL with the help of parameter protocol. We’ll get one more pet object which we are decoding here from the pet JSON we are passing with updated pet data. That is why I’ve named them as ‘pet’ and ‘updatedPet’ in the closure parameters.</li><li>In step 3 we update all the data of the pet which we are getting. We are doing updations with pet object because it contains the ‘id’ of the pet against which we’ll be updating the data.</li><li>Here we save the pet object in the table with updated data.</li></ol><p><strong>Route</strong></p><p>Route for this web service will be a bit different. Add following code in the route function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/595c59df2c7844d95e73aa7662555468/href">https://medium.com/media/595c59df2c7844d95e73aa7662555468/href</a></iframe><p>Here the URL will remain the same as we’ve added pet as path component but, I’ve written Pet.parameter as path component as well. As mentioned above I’ll have to append the pet id in the URL. And at the end we are using the updatePet function of the PetController. Now run the code and test it with Postman. The request and response should look like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4XIuyhhI_5waTjba_dbAVA.png" /><figcaption>Update pet</figcaption></figure><p>Here you can clearly see that I’ve appended the pet id in URL. And in body, I’ve updated the name as ‘Tomas’ and in output, you can see that. For more clarification, you can check the same in the table with the help of Postico.</p><h4>4. Delete</h4><p>To delete the user we’ll use the HTTP DELETE method and again alike update, we’ll pass the pet id in the URL. Add following function to PetController.swift</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/445d372bc42a85d5015b87e01fc11aa9/href">https://medium.com/media/445d372bc42a85d5015b87e01fc11aa9/href</a></iframe><ol><li>We’ve created a function named ‘deletePet’ which accepts HTTP request and return HTTP status.</li><li>We get the pet from the table with the help of parameter we’ve appended on URL</li><li>We delete that pet with the help of delete function</li><li>Here we transform the result with HTTP status because delete function returns nothing.</li></ol><p><strong>Route</strong></p><p>Add following lines in routes function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18e26bb0d7b9f32d88f7b1143ab58e0a/href">https://medium.com/media/18e26bb0d7b9f32d88f7b1143ab58e0a/href</a></iframe><p>It is almost the same as the update one, the only change is we change the method to delete instead of put.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FLJnA13jCK3K8g%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FLJnA13jCK3K8g%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FLJnA13jCK3K8g%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/a68a44806bbf7d73042e57696d780406/href">https://medium.com/media/a68a44806bbf7d73042e57696d780406/href</a></iframe><p>Yes. That’s it. Isn’t it very simple with swift to write web services :)</p><h3>Summary</h3><p>We started learning how to create a database with PostgreSQL. Then we added the required dependencies in Package.swift. We updated configurations for PostgreSQL. We created a pet table in the database and then with the help of PetController, we performed the CRUD operations.</p><p>You’ll be able to get the whole code <a href="https://aditya422.github.io/Vapor-CRUDOperations/">here</a>.</p><h3>Where to go from here</h3><p>In the next article, we’ll learn to provide filtered and sorted the responses. We’ll learn to add validations and also we’ll learn to encrypt and decrypt the data.</p><p>Till then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*Y7BMj4sWJqCuE9N94UPkCQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cddc3e622fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/crud-operations-with-vapor-8cddc3e622fc">CRUD operations with Vapor</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with server side Swift with Vapor]]></title>
            <link>https://medium.com/macoclock/getting-started-with-server-side-swift-with-vapor-84497d9b7257?source=rss-abd6e3231e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/84497d9b7257</guid>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[server-side-swift]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[vapor]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Aditya Shinde]]></dc:creator>
            <pubDate>Sat, 02 May 2020 14:22:42 GMT</pubDate>
            <atom:updated>2021-05-16T11:52:23.014Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*JX1K26Nervyu3oq8-aTU_Q.jpeg" /></figure><h3>Getting started with server-side Swift with Vapor</h3><p>In 2014 WWDC Apple introduced Swift, a brand new programming language with which we can write apps for iOS and Mac OS. Writing code in Swift is great fun and I simply love this language. In 2016 Apple also announced Swift support for Linux and we can write server-side code with swift.</p><p>Being an iOS developer I was very curious about how the server code is written, especially the web services which we consume in our mobile apps. This curiosity drives me to learn more about server-side swift.</p><p>There are multiple frameworks available to write server codes with swift like Kitura(developed by IBM), Perfect, Vapor, etc. We will be writing server-side code in swift with Vapor.</p><p><strong>Why Vapor?</strong></p><ul><li><strong>Fluent:</strong> Fluent is an ORM provided by Vapor. With Fluent we can create Models for tables in the database. We can query tables as very similar as we query our entities in Core-Data in iOS. Due to ORM, you won’t have to write direct database queries.</li><li><strong>Continuous evolution:</strong> We get continuous updates of this framework with new Swift versions. Vapor 3.0 was completely re-written to support Apple’s non-blocking networking framework Swift NIO. That means Vapor is a non-blocking framework. You don’t have to worry if 2 API calls are hit by the user at the same time. Vapor itself will take care of that.</li><li><strong>Huge community:</strong> The last and most important reason I recommend Vapor over others is its huge community. Vapor has a huge community on different platforms like Slack, Discord. These are the places where you get instant help.</li></ul><p><strong>Install Vapor</strong></p><ul><li>To install Vapor refer to <a href="https://docs.vapor.codes/3.0/install/macos/">this</a> link for mac OS. For Linux refers to <a href="https://docs.vapor.codes/3.0/install/ubuntu/">this</a> link.</li></ul><p><strong>First Vapor Project</strong></p><ul><li>Go to the desired directory path on the terminal and hit command</li></ul><pre>vapor new Todo</pre><p>You can see that a new folder has been created at the path you had selected with the project name.</p><ul><li>Now we have to go to the project directory path. Hit following command on terminal</li></ul><pre>cd Todo</pre><ul><li>Now hit following command</li></ul><pre>vapor xcode</pre><ul><li>Now open the project in Xcode and in run scheme select My Mac and build and run the project as shown in the following image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*OySl5dIJRoZYCfTDu--8Qg.png" /><figcaption>Select Run Scheme and device My Mac to run the project</figcaption></figure><ul><li>If you see <strong>Server starting on </strong><a href="http://localhost:8080/"><strong>http://localhost:8080</strong></a><strong>. </strong>Now hit the localhost URL on the browser and you’ll see the text <strong>It works! </strong>Congratulations. You’ve run your first Swift server code successfully. Refer following image</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0n9ukxW-iYfYM56ZGPN0A.png" /><figcaption>Output when you hit localhost URL in browser</figcaption></figure><p><strong>Understanding the project structure</strong></p><ul><li><strong>Package.swift</strong></li></ul><p>This file manages all dependencies we need in our project. Here you can see two dependencies, Vapor itself and Fluen-SQLite which is ORM provided by Vapor.</p><ul><li><strong>Todo.swift</strong></li></ul><p>The table will have two columns id and title. You can see Todo is confirming protocols like SQLiteModel, Content, Migration, and Parameter. For now let us only talk about content. Content confirms swift protocol codable. All of us know how codable has made our lives easier to create models from the JSON response. Content does a similar thing here. If your model is confirming content protocol, you don’t have to do anything else to return it as JSON in API response.</p><ul><li><strong>configure.swift</strong></li></ul><p>As its name suggests, everything we need in the app has to be configured here. You can see the last line in the code snippet where we are registering the model. Unless and until you register the model in this file like above, the respective table won’t be created in the database.</p><ul><li><strong>TodoController.swift</strong></li></ul><p>All the operations we have to do with Todo table with the help of web services, we’ll be doing them in this file. Here you can see the functions to fetch all todos and functions to create and delete todos.</p><ul><li><strong>routes.swift</strong></li></ul><p>In this file we call the services with the functions written in the controller with the URL endpoints. When you run the app for the first time, it printed “It works!” on the browser. You can see it in the first route. Now if you append “hello” on the localhost URL, the final URL would be <a href="http://localhost:8080/hello">http://localhost:8080/hello</a> and you’ll see “Hello, world!” as an output on the browser. Refer following image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWPq7AjEOAQS74iJIksreQ.png" /><figcaption>Response of hello world</figcaption></figure><p>You can test create, get all, and delete service outputs with REST clients like the postman.</p><p><strong>What Next</strong></p><p>Here we just explored the template project created by Vapor. In the next article, we’ll create a new table with the PostgreSQL database and will try to perform CRUD operations and we’ll also learn how to query the tables in the database.</p><p>Till then, Keep Calm and Keep Coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84497d9b7257" width="1" height="1" alt=""><hr><p><a href="https://medium.com/macoclock/getting-started-with-server-side-swift-with-vapor-84497d9b7257">Getting started with server side Swift with Vapor</a> was originally published in <a href="https://medium.com/macoclock">Mac O’Clock</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>