Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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 Full-Stack Development with Swift

You're reading from   Hands-On Full-Stack Development with Swift Develop full-stack web and native mobile applications using Swift and Vapor

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788625241
Length 356 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ankur Patel Ankur Patel
Author Profile Icon Ankur Patel
Ankur Patel
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting Started with Server Swift FREE CHAPTER 2. Creating the Native App 3. Getting Started with Vapor 4. Configuring Providers, Fluent, and Databases 5. Building a REST API using Vapor 6. Consuming API in App 7. Creating Web Views and Middleware 8. Testing and CI 9. Deploying the App 10. Adding Authentication 11. Building a tvOS App 12. Other Books You May Enjoy

Routing in Vapor


Routing is a very important feature of any web application. It is the interface through which you can access the application and perform certain actions on it. HTTP is the protocol used in routing. We went through the basics of HTTP in Chapter 1Getting Started with Server Swift, and as you might be aware, HTTP protocol requires a method, a path, a set of headers, and an optional body to make a request to the server. The server then responds back with a message that contains a status code, a set of Response headers, and a message body.

HTTP methods

For most of the web, there are five commonly used HTTP methods, which are as follows:

  • GET
  • POST
  • PATCH
  • PUT
  • DELETE
  • OPTIONS

There are also other methods that are less used and can be passed in the request to a web application. If it is able to handle it, the routing rules will determine who should be handling the request.

Vapor's droplets give us easy-to-use APIs to construct routes for these commonly used HTTP methods. All we need to do is...

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 $19.99/month. Cancel anytime
Banner background image