💧 A server-side Swift HTTP web framework.

What's New

Add definition for application/json-seq

This patch was authored and released by @gwynne.

Also fixes a couple of minor formatting and wording issues in a couple of comments.

I would've added ContentConfiguration for the .jsonSequence media type, but its most effective use in a Vapor context would be via Request.Body.drain(_:) and Response.Body.init(stream:), and ContentEncoder/ContentDecoder are not really set up for that. Here is a supposed-to-be-quick contrived example (which mostly has the effect of showcasing that BodyStreamWriter could desperately use some Concurrency extensions!):

app.get("json-stream") { req -> Response in
    var headers = HTTPHeaders()
    headers.contentType = .jsonSequence
    return Response(status: .ok, headers: headers, body: .init(stream: { writer in
        _ = writer.eventLoop.performWithTask {
            do {
                let stream = AsyncStream<Int> { c in Task.detached {
                    for _ in 0..<100 {
                        try! await Task.sleep(nanoseconds: 1_000_000_000)
                        c.yield(Int.random(in: .min ... .max))
                } }
                for await i in stream {
                    var buffer = ByteBufferAllocator().buffer(capacity: 0)
                    buffer.writeBytes([0x1e]) // <RS>
                    try JSONEncoder().encode(["i": i], into: &buffer)
                    buffer.writeBytes([0x0a]) // <LF>
                    try await writer.eventLoop.flatSubmit { writer.write(.buffer(buffer)) }.get()
                try await writer.eventLoop.flatSubmit { writer.write(.end) }.get()
            } catch {
                try? await writer.eventLoop.flatSubmit { writer.write(.error(error)) }.get()


Documentation Team Chat MIT License Continuous Integration Swift 5.2 Twitter

Vapor is an HTTP web framework for Swift. It provides a beautifully expressive and easy-to-use foundation for your next website, API, or cloud project.

Take a look at some of the awesome stuff created with Vapor.

💧 Community

Join the welcoming community of fellow Vapor developers on Discord.

🚀 Contributing

To contribute a feature or idea to Vapor, create an issue explaining your idea or bring it up on Discord.

If you find a bug, please create an issue.

If you find a security vulnerability, please contact as soon as possible.

💛 Sponsors

Support Vapor's development by becoming a sponsor.

Broken Hands Monstarlab Transeo omrd Jari

💚 Backers

Support Vapor's development by becoming a backer.



  • Swift Tools 5.2.0
View More Packages from this Author


Last updated: Thu Dec 02 2021 10:05:38 GMT-0500 (GMT-05:00)