The ASAPServer
With the entire environment set, we can finally implement the ASAP Server.
The Products
In a real server, the products are probably saved in a database, but in our simple implementation, we will save the products in a file—the same file we used in the app.
So, let's start the implementation by saving the products.json
file at the same level of makefile.
A DBRepository
class will abstract the connection with the storage, making it easy to switch to a database, as we did in the app:
import Foundation let dbRepository = DBRepository() class DBRepository { func allProducts() -> String { print("Get /products") do { let productsAsNSString = try NSString(contentsOfFile: "products.json", encoding: NSUTF8StringEncoding) #if os(Linux) return productsAsNSString.bridge() ...
Get Swift 2 By Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.