From the course: Using Vapor with SQL and NoSQL Databases
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Creating a RESTful interface - Swift Tutorial
From the course: Using Vapor with SQL and NoSQL Databases
Creating a RESTful interface
- [Instructor] In this lesson we're going to discuss making a controller object into a RESTful resource. In previous lessons, we've created our own specific routes to perform tasks such as create, show, delete and so forth, and while we can do that, we're essentially creating multiple routes and end points by doing so and this is okay. However, Vapor can make this process even easier for us. All we need to do is make a controller object conform to the resource representable protocol and doing so will ensure that our controller conforms to standard RESTful structure. So let's start by creating a new controller that we're going to call, RESTController.swift. I'll then regenerate my vapor xcode project. And then, let's go ahead and go into our class. In here, the first thing I'm going to do is import Vapor, HTTP, and Foundation. Then I'm going to define our class. With this, I am now conforming to the ResourceRepresentable protocol, and if we were to take a look at the Definition, we'll…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.