File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -521,6 +521,36 @@ $ carthage update
521521
522522Drag the built framework into your Xcode project.
523523
524+ ## Usage with Vapor
525+
526+ ``` swift
527+ extension XMLEncoder : ContentEncoder {
528+ public func encode <E : Encodable >(
529+ _ encodable : E,
530+ to body : inout ByteBuffer,
531+ headers : inout HTTPHeaders
532+ ) throws {
533+ headers.contentType = .xml
534+
535+ // Note: You can provide an XMLHeader or DocType if necessary
536+ let data = try self .encode (encodable)
537+ body.writeData (data)
538+ }
539+ }
540+
541+ extension XMLDecoder : ContentDecoder {
542+ public func decode <D : Decodable >(
543+ _ decodable : D.Type ,
544+ from body : ByteBuffer,
545+ headers : HTTPHeaders
546+ ) throws -> D {
547+ // Force wrap is acceptable, as we're guaranteed these bytes exist through `readableBytes`
548+ let body = body.readData (length : body.readableBytes )!
549+ return try self .decode (D.self , from : body)
550+ }
551+ }
552+ ```
553+
524554## Contributing
525555
526556This project adheres to the [ Contributor Covenant Code of
You can’t perform that action at this time.
0 commit comments