- 
                Notifications
    
You must be signed in to change notification settings  - Fork 14
 
Middleware
        Josh Wright edited this page Jan 14, 2021 
        ·
        4 revisions
      
    A Middleware is used to intercept either incoming Requests or
outgoing Responses. Using futures, they can do something
with those, either synchronously or asynchronously.
public protocol MiddlewareUsage:
// Example synchronous middleware
struct SyncMiddleware: Middleware {
    func intercept(_ request: Request, next: @escaping Next) throws -> EventLoopFuture<Response>
        ... // Do something with `request`.
        // Then continue the chain. Could hook into this future to
        // do something with the `Response`.
        return next(request)
    }
}
// Example asynchronous middleware
struct AsyncMiddleware: Middleware {
    func intercept(_ request: Request, next: @escaping Next) throws -> EventLoopFuture<Response>
        // Run some async operation
        Services.db
            .runRawQuery(...)
            .flatMap { someData in
                // Set some data on the request for access in
                // subsequent Middleware or request handlers.
                // See `HTTPRequst.set` for more detail.
                request.set(someData)
                return next(request)
            }
    }
}Intercept a requst, returning a future with a Response representing the result of the subsequent handlers.
func intercept(_ request: Request, next: @escaping Next) throws -> EventLoopFuture<Response>Be sure to call next when returning, unless you don't want the request to be handled.
- request: The incoming request to intercept, then pass along the handler chain.
 
Any error encountered when intercepting the request.
Generated at 2021-01-13T22:24:59-0800 using swift-doc 1.0.0-beta.5.
Alchemy
Types
- AlterTableBuilder
 - BCryptDigest
 - BasicAuthMiddleware
 - BcryptError
 - BelongsToRelationship
 - CORSMiddleware
 - CORSMiddleware.AllowOriginSetting
 - CORSMiddleware.Configuration
 - ColumnType
 - CreateColumn
 - CreateColumnBuilder
 - CreateIndex
 - CreateTableBuilder
 - DatabaseConfig
 - DatabaseError
 - DatabaseField
 - DatabaseKeyMappingStrategy
 - DatabaseValue
 - DayUnit
 - Env
 - FrequencyTyped
 - Grammar
 - HTTPAuth
 - HTTPAuth.Basic
 - HTTPAuth.Bearer
 - HTTPBody
 - HTTPError
 - HasManyRelationship
 - HasOneRelationship
 - HasRelationship
 - HourUnit
 - JoinClause
 - JoinType
 - Launch
 - Log
 - MIMEType
 - MinuteUnit
 - ModelQuery
 - MySQLDatabase
 - Operator
 - OrderClause
 - OrderClause.Sort
 - OrderedDictionary
 - PapyrusClientError
 - PathParameter
 - PathParameter.DecodingError
 - PostgresDatabase
 - Query
 - Request
 - Response
 - Router
 - RuneError
 - SQL
 - SQLJSON
 - Scheduler
 - Schema
 - SecondUnit
 - Services
 - Socket
 - StaticFileMiddleware
 - StringLength
 - Thread
 - TokenAuthMiddleware
 - WeekUnit
 - Weekday
 - WhereBoolean
 - WhereColumn
 - WhereIn
 - WhereIn.InType
 - WhereNested
 - WhereRaw
 - WhereValue