Skip to content

Commit f84871d

Browse files
authored
Update README.md
1 parent 1b5011b commit f84871d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,36 @@ $ carthage update
521521

522522
Drag 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

526556
This project adheres to the [Contributor Covenant Code of

0 commit comments

Comments
 (0)