Book Image

Hands-On Full-Stack Development with Swift

By : Ankur Patel
Book Image

Hands-On Full-Stack Development with Swift

By: Ankur Patel

Overview of this book

Making Swift an open-source language enabled it to share code between a native app and a server. Building a scalable and secure server backend opens up new possibilities, such as building an entire application written in one language—Swift. This book gives you a detailed walk-through of tasks such as developing a native shopping list app with Swift and creating a full-stack backend using Vapor (which serves as an API server for the mobile app). You'll also discover how to build a web server to support dynamic web pages in browsers, thereby creating a rich application experience. You’ll begin by planning and then building a native iOS app using Swift. Then, you'll get to grips with building web pages and creating web views of your native app using Vapor. To put things into perspective, you'll learn how to build an entire full-stack web application and an API server for your native mobile app, followed by learning how to deploy the app to the cloud, and add registration and authentication to it. Once you get acquainted with creating applications, you'll build a tvOS version of the shopping list app and explore how easy is it to create an app for a different platform with maximum code shareability. Towards the end, you’ll also learn how to create an entire app for different platforms in Swift, thus enhancing your productivity.
Table of Contents (19 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
Index

Chapter 5. Building a REST API using Vapor

In the previous chapter, we covered several topics related to Vapor applications, such as how to extend the functionality of a Vapor application using Providers, and we dove into the Fluent provider as it is the most-used Provider in any Vapor application. It is also Vapor's and Swift's ORM to create, read, update, and delete data in the database using a high-level API. In this chapter, we will cover another important topic in building web applications that are related to routing, especially when building an API server.

Giving structure to our routes makes our applications easier to manage and easier for others to consume. There are several popular patterns in the industry when it comes to creating routes for your application, especially when building API routes to perform actions, such as create, read, update, and delete, on a specific type of item. If we look at our Shopping List iOS application, we have a Shopping List and an Item Model. We can...