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.

    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.

    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.

    Throws

    Socket.Error if an error occurred while reading from a socket.

    Declaration

    Swift

    public class func readBodyData(with reader: RouterRequest) throws -> Data

    Parameters

    with

    the socket reader.

    Return Value

    data for the body.