BodyParser
public class BodyParser: RouterMiddleware
Router middleware for parsing the body of the request.
-
Initializes a BodyParser instance. Needed since default initalizer is internal.
Declaration
Swift
public init()
-
Handle the request, i.e. parse the body of the request.
Parameter
Parameter request: the router request.Parameter
Parameter response: the router response.Parameter
Parameter next: the closure for the next execution block.Declaration
Swift
public func handle(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void) throws
Parameters
request
the router request.
response
the router response.
next
the closure for the next execution block.
-
Parse the body of the incoming message.
Parameter
Parameter message: message coming from the socket.Parameter
Parameter contentType: the content type as a String.Returns
the parsed body.Declaration
Swift
public class func parse(_ message: RouterRequest, contentType: String?) -> ParsedBody?
Parameters
message
message coming from the socket.
contentType
the content type as a String.
Return Value
the parsed body.
-
Read the body data of the request.
Parameter
Parameter with: the socket reader.Throws
Socket.Error if an error occurred while reading from a socket.Returns
data for the body.Declaration
Swift
public class func readBodyData(with reader: RouterRequest) throws -> Data
Parameters
with
the socket reader.
Return Value
data for the body.