Last active
May 7, 2016 22:47
-
-
Save tanner0101/54e0fc4714b26d00c39a to your computer and use it in GitHub Desktop.
Vapor Protocols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Vapor | |
/** | |
* This protocol defines router objects that can be used to relay | |
* different paths to the application | |
*/ | |
public protocol RouterDriver { | |
func route(request: Request) -> Request.Handler? | |
func register(route: Route) | |
} | |
public protocol ServerDriver { | |
func boot(port port: Int) throws | |
func halt() | |
var delegate: ServerDriverDelegate? { get set } | |
} | |
public protocol ServerDriverDelegate { | |
func serverDriverDidReceiveRequest(request: Request) -> Response | |
} | |
/* Logger protocol. Custom loggers must conform | |
to this protocol | |
*/ | |
public protocol LogDriver { | |
func log(level: Log.Level, message: String) | |
} | |
/** | |
* Classes that conform to `HashDriver` may be set | |
* as the `Hash` classes hashing engine. | |
*/ | |
public protocol HashDriver { | |
/** | |
* Given a string, this function will | |
* return the hashed string according | |
* to whatever algorithm it chooses to implement. | |
*/ | |
func hash(message: String, key: String) -> String | |
} | |
/** | |
Intercept and modify `Request`s and `Response`s | |
using middleware. Create a class that conforms to | |
the `Middleware` protocol, then append the class | |
to the `Server`s `middleware` array. | |
*/ | |
public protocol Middleware { | |
/** | |
Here is where you implement your custom `Middleware` | |
logic. Look at the `SessionMiddleware` to see an | |
example of `Middleware` being used. | |
Call `handler(request)` somewhere inside your custom | |
handler to get the `Response` object. | |
*/ | |
static func handle(handler: Request.Handler) -> Request.Handler | |
} | |
/* | |
Fluent | |
*/ | |
import Fluent | |
public protocol Driver { | |
func fetchOne(table table: String, filters: [Filter]) -> [String: String]? | |
func fetch(table table: String, filters: [Filter]) -> [[String: String]] | |
func delete(table table: String, filters: [Filter]) | |
func update(table table: String, filters: [Filter], data: [String: String]) | |
func insert(table table: String, items: [[String: String]]) | |
func upsert(table table: String, items: [[String: String]]) | |
func exists(table table: String, filters: [Filter]) -> Bool | |
func count(table table: String, filters: [Filter]) -> Int | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment