Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Server-Side Web Development with Swift

You're reading from   Hands-On Server-Side Web Development with Swift Build dynamic web apps by leveraging two popular Swift web frameworks: Vapor 3.0 and Kitura 2.5

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781789341171
Length 404 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Angus Yeung Angus Yeung
Author Profile Icon Angus Yeung
Angus Yeung
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Introducing Server-Side Swift FREE CHAPTER 2. Getting Started with Vapor and Kitura 3. Building Your First Web App 4. Debugging and Testing 5. Setting Up Routes and Controllers 6. Working with Template Engines 7. Bootstrapping Your Design 8. Employing Storage Framework 9. Adding Authentication 10. Understanding Technologies for Web Services 11. Designing for API Gateway 12. Deploying to the Cloud 13. Developing an iPhone Client 14. Developing Microservices 15. Vapor Boilerplate Project 16. Kitura Boilerplate Project 17. Other Books You May Enjoy

Adding more routes in Vapor

This section will show you how to add more routes in Vapor:

  1. Open the routes.swift file from Project Navigator on Xcode's left panel and add the following code to the line right before the closing brace at the bottom:
. . .
router.get("greet", String.parameter) { req -> String in // [1]
let guest = try req.parameters.next(String.self) // [2]
return "Hi \(guest), greetings! Thanks for visiting us." // [3]
}
. . .
  1. The preceding code does three things:
    1. Add a new route using greet as the first parameter from the path components and specifying the second parameter to be a string.
    2. Extract the guest string from the request's next item in its parameters list.
    3. Interpolate the guest string in the string returning to the client.

If you build and run your project again, you can see the following output by directing your...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime