$ grep -r Tag: «vapor»

-rw-r--r-- 2.3K Mar 28, 2026 · 506D0D0 · ~2 min

CouchDB client for Swift 2.4.0

swift couchdb swift package vapor open source

Highlights

  • Refactored the internal request pipeline in CouchDBClient to use cleaner async/await-style flows and reduce duplicated response handling logic.
  • Improved buffering and decoding paths for raw and typed requests, with a focus on safer EventLoopGroup execution and better performance in response processing.
  • Expanded test coverage around EventLoopGroup-backed request execution, including raw and typed get, raw and typed find, attachment download, Mango index listing, and Mango query explanation.
  • Refreshed user-facing documentation across the README, DocC articles, and tutorials.
  • Updated documentation tooling for newer DocC workflows, including Markdown export support.

API and Behavior Improvements

  • Added and refined EventLoopGroup support across more CouchDBClient request paths.
  • Improved internal error-handling paths and response decoding behavior for CouchDB operations.
  • Simplified request helper layering and reduced duplicated request/response processing code.
  • Improved attachment-related behavior and accompanying tests.
  • Added visionOS to supported platforms in the package manifest.

Documentation

  • Fixed and refreshed README examples for CRUD and Mango query usage.
  • Updated DocC landing pages to better reflect the current API surface.
  • Corrected the Advanced Mango Query tutorial snippets to match the current typed query API.
  • Corrected Vapor tutorial examples.
  • Fixed Hummingbird tutorial package setup and dependency snippets.
  • Updated buildDocs.sh to support:
    • configurable output and hosting base path
    • static hosting content embedding
    • experimental Markdown output
    • Markdown manifest generation
  • Added a post-processing step in buildDocs.sh that injects a relative Markdown link into generated DocC HTML pages.

Tooling and Dependencies

  • Updated package dependencies in Package.resolved.
  • Updated the Ubuntu build workflow Swift version matrix.

CouchDB Client on GitHub | Documentation with examples and tutorials.

Star Fork

[↵] open page couchdb-client-for-swift-2-4-0.md
-rw-r--r-- 1.3K Aug 1, 2025 · 508C136 · ~1 min

CouchDB client for Swift 2.3.0

swift couchdb swift package vapor open source

CouchDB client for Swift 2.3.0

Recently, I've implemented a feature that I wanted to add to the CouchDB Swift client for a long time. It's Mango Queries support. Finally, it is done in 2.3.0. Feels like the last remaining big feature.

Changelog:

  • Introduced a robust and type-safe MangoQuery API for building complex selectors, projections, sorting, and pagination in CouchDB.
  • Added support for specifying indexes via useIndex in queries to optimize performance.
  • Added first-class support for uploading, downloading, and deleting document attachments (files/images).
  • Comprehensive Attachments API test suite ensures reliability for file operations.
  • Added models and API for creating, listing, and managing Mango indexes (MangoIndex, IndexDefinition).
  • Tutorial and code samples for creating indexes are now included in documentation.
  • Added support for CouchDB Mango _explain endpoint via MangoExplainResponse to inspect how queries are executed and which indexes are used.

CouchDB Client on GitHub | Documentation with examples and tutorials.

Star Fork

[↵] open page couchdb-client-for-swift-2-3-0.md
-rw-r--r-- 1.4K Jul 31, 2025 · 043C479 · ~2 min

A story of one bug in Leaf

swift vapor leaf open source

A story of one bug in Leaf

This website is working on Vapor - a server-side Swift framework. It's pretty old, popular, and well known.

I’ve used it for a few years already and always liked that it's fast and doesn't require a lot of memory on the server.

I'm keeping all dependencies up to date. But recently I've noticed that the website started to eat a lot of memory. It starts with about 20 mb of memory usage, but after a few weeks, I found that it ate about 750 mb on the server.

That's a lot for such a simple website, so I started digging. After reviewing the site code (which I didn't change for a long time), I couldn't find any issues (and AI agents too).

I use Leaf - a template engine from the Vapor team to render HTML. And there was an open issue on their GitHub repo describing exactly the same problem.

So I've asked Copilot to help me debug what's wrong. Pretty quickly, it added some new tests to my fork that did a lot of renders in a cycle. And leak util found retain cycles. So I fixed that with some weak annotation, but during the review of my PR, a maintainer suggested to just use unowned.

And that's it. 2 lines of code fixed memory growth. It's hard to believe, but after a few hours since the deploy, the website still takes only 2 mb of memory. So I'm very proud of myself today.

Morale: contribute to the open-source project that you use.

[↵] open page a-story-of-one-bug-in-leaf.md
-rw-r--r-- 1.2K Apr 16, 2025 · B2756B3 · ~1 min

CouchDB client for Swift version 2

swift couchdb swift package vapor open source

CouchDB client for Swift version 2

Recently, I’ve released a few new versions of the CouchDB client for Swift. The latest version is version 2, and it includes several key changes:

  • Updated the minimum required Swift tools version to 6.0.
  • Adopted Swift Concurrency. CouchDBClient has been updated to be an actor.
  • Renamed the library from couchdb-vapor to couchdb-swift to better reflect its purpose as a general CouchDB client for Swift, beyond Vapor-specific use cases.
  • Made some changes to the initializer. Instead of passing a lot of parameters, it now accepts a Config structure.
  • You can pass your own HTTPClient instance to be used in the client.
  • Added translations for error messages.
  • Introduced a dedicated tutorial for integrating CouchDBClient with the Hummingbird server-side framework.
  • Added a shutdown() method to properly release resources associated with the HTTPClient.

CouchDB Client on GitHub | Documentation with examples and tutorials.

Star Fork

[↵] open page couchdb-client-for-swift-version-2.md
-rw-r--r-- 1.2K Apr 8, 2024 · BA68FE9 · ~1 min

Swift CouchDB client 1.5.0

swift couchdb swift package vapor open source

Swift CouchDB client 1.5.0

And here we go, one more new version of the CouchDB client library. After the recent post about 1.4.0, Swift on Server released a new version of async-http-client that includes a new implementation of the client singleton. Now it's HTTPClient.shared, so I've updated the CouchDB library to adopt that change. This also means that you no longer need to call httpClient.syncShutdown() if the singleton is used. Additionally, they've bumped the minimum Swift version to 5.8 (which I aslo did in version 1.4.0 of the CouchDB client library). So, I'm keeping the library up to date.

Changelog:

  • Bumped the minimum version of async-http-client to the new 1.21.0. If you can't use it in your project, you can still stay on 1.4.0.
  • The library will now use HTTPClient.shared (new in async-http-client 1.21.0) internally for requests if no EventLoopGroup is provided.
  • No more internal calls for httpClient.syncShutdown() in case of HTTPClient.shared usage.

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-5-0.md
-rw-r--r-- 1.2K Apr 8, 2024 · 08DA6BF · ~1 min

Swift CouchDB client 1.4.0

swift couchdb swift package vapor open source

Swift CouchDB client

A new version of CouchDB Client has been released:

  • The library migrated from HTTPClient.Response to HTTPClientResponse, which is similar to HTTPClient.Response but used for the Swift Concurrency API. It also migrated from HTTPClient.Body to HTTPClientRequest.Body. These changes impact the get and find methods. Old methods are marked as deprecated, please refer to the documentation for the updated methods.
  • The minimum Swift version is now 5.8.
  • The CouchDBRepresentable protocol is now marked as Codable.
  • Additionally, a new data model called RowsResponse has been added. It accepts a generic CouchDBRepresentable type, making it easier to retrieve rows from a database. For example:
    let decodeResponse = try JSONDecoder().decode(RowsResponse<MyApp>.self, from: data)
  • Lastly, there have been small improvements in the documentation and tutorials.

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-4-0.md
-rw-r--r-- 1.1K Apr 4, 2024 · 0427246 · ~1 min

A middleware for Vapor 4 routing to trim a slash in url path

vapor code snippets шпаргалки swift server side swift

It’s a common thing for a website or a backend to allow URLs like mySite.com/webpage and mySite.Com/webpage/ for the same page. These pages are different URLs for a search engine. If you want to avoid duplicates, you can add a simple middleware to trim the ending slash and redirect a user.

Here’s an example code for such a middleware class for Vapor 4:

final class TrimSlashInPathMiddleware: Middleware {
    func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
        if request.url.path.count > 1, request.url.path.hasSuffix("/") {
            let newPath = String(request.url.path.trimmingSuffix(while: { $0 == "/" }))
            let response = request.redirect(to: newPath, redirectType: .permanent)
            return request.eventLoop.makeSucceededFuture(response)
        }
        return next.respond(to: request)
    }
}

Just add it to configure.swift file:

import Vapor

public func configure(_ app: Application) throws {
    app.middleware.use(TrimSlashInPathMiddleware())

    app.http.server.configuration.port = 8081

    try routes(app)
}

Works with Vapor 4.92.5.

[↵] open page a-middleware-for-vapor4-to-trim-a-slash-in-url-path.md
-rw-r--r-- 836B Mar 29, 2024 · EA452FF · ~1 min

Swift CouchDB client 1.3.2

swift couchdb swift package vapor open source

Swift CouchDB client

Recently, there have been a couple of new releases for my Swift CouchDB library. Here are the recent changes:

  • dateDecodingStrategy and dateEncodingStrategy can now be passed as parameters for get, update and insert methods.
  • Added a check to handle expired authentication cookies.
  • Comparing the set-cookie header in the response as lowercased.
  • Introduced new methods to utilize the _find API, allowing you to find documents using a declarative JSON querying syntax
  • Fixed an issue where the update method didn’t use dateEncodingStrategy parameter.

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-3-2.md
-rw-r--r-- 973B Dec 26, 2022 · BE2067B · ~1 min

Swift CouchDB client 1.2.1

swift couchdb swift package vapor open source

Swift CouchDB client 1.2.1

Just a small update for Swift CouchDB client lib with couple new methods that I needed by myself:

  • Added a new method to create a database [docs].
  • Added a new method to delete a database [docs].
  • Added a new method to check if a database exists [docs].
  • Every request handles unauthorised errors now.
  • CouchDBClientError model has a description text now.

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-2-1.md
-rw-r--r-- 1.1K Oct 4, 2022 · A996DD3 · ~1 min

Swift CouchDB client 1.2.0

swift couchdb swift package vapor open source

Swift CouchDB client 1.2.0

Couple months ago I started learning Apple's DocC tool that generates documentation from your source code. I've decided to use as many features as possible so I took my small lib CouchDB Client and added docs to every method including usage examples that Xcode will show in the autocomplete popup. As it often happens, during adding docs and examples I found that many things in the library can be done in a much better way. So I've updated existing methods and added some more that can take a doc as a param and use generic types.

Next step was tutorials. Apple allows devs to create exactly the same tutorials as they have for SwiftUI on their own website. So I've added a couple. They're also part of the repo on GitHub.

Pretty sure that I've spent more time on the documentation than on the lib itself but I hope it's worth it.

CouchDB Client on GitHub | Documentation with examples and tutorials.

[↵] open page swift-couchdb-client-1-2-0.md
-rw-r--r-- 1.0K Oct 1, 2018 · 66FB865 · ~2 min

Benchmarks: Vapor 3 vs. Vapor 2

swift backend vapor ubuntu benchmark

After migrating (almost rewriting) my small project from Vapor 2 to Vapor 3 I've run benchmarks to compare performance. I didn't run benchmarks for the last version of Vapor 2.x so I will compare Vapor 2.1.0 to results of Vapor 3.1.0.

My server configuration:

  • 2 GB RAM
  • 1 CPU Core
  • SSD
  • 125 MBPS Out
  • Ubuntu 16.04.2 LTS
  • CouchDB

Benchmark from other server has been launched as:

wrk -t4 -c20 -d5m https://my_url

API just gets some data from CouchDB and returns it as JSON. Vapor project has been compiled with Swift 4.2.

[↵] open page benchmarks-vapor-3-vs-vapor-2.md
-rw-r--r-- 374B Sep 5, 2017 · E5E50B4 · ~1 min

openssl and Vapor 2

vapor swift шпаргалки

I ran into a problem where a Vapor 2 project stopped compiling on Ubuntu. More precisely, one of its dependencies, Crypto. It turned out that because of an added repository containing newer versions of some libraries, it would not compile. Writing it down here — I had to downgrade:

apt install libssl-dev=1.0.2g-1ubuntu4.10
apt install openssl=1.0.2g-1ubuntu4.10
[↵] open page openssl-i-vapor-2.md
-rw-r--r-- 919B Jun 14, 2017 · 5C60537 · ~2 min

Benchmarks: Vapor 2 vs. Vapor 1

swift backend vapor ubuntu

After migrating my pet project from Vapor 1 to Vapor 2 I've run benchmarks to compare performance. I didn't run benchmarks for the last version of Vapor 1.x which is 1.5.15 so I will compare Vapor 2.1.0 to results of Vapor 1.2.5 that I have from my last results.

My server:

  • 2 GB RAM
  • 1 CPU Core
  • SSD
  • 125 MBPS Out
  • Ubuntu 16.04.2 LTS
  • CouchDB

Benchmark from other server was launched as:

wrk -t4 -c20 -d5m https://my_url

API just gets some data from CouchDB and returns it as JSON. Vapor project has been compiled with Swift 3.1.1.

[↵] open page benchmarks-vapor-2-vs-vapor-1.md
-rw-r--r-- 1.1K Feb 9, 2017 · F3580BC · ~1 min

Space In Box Website

swift приложения space in box vapor

Space In Box website

I decided to move the information about my apps from apps.arm1.ru to a separate domain. Since I once started publishing them under the name Space In Box, the domain matches: spaceinbox.me. I decided to remove apps that were no longer relevant or available and use vector graphics as much as possible everywhere (icons, logos), because on Retina screens raster graphics really hurts the eyes.

It was a great excuse to build something in Swift with the Vapor framework, and so far everything I needed worked out. Updating it when something changes in the logic is of course harder, because you have to rebuild everything on the server each time, and that takes 3–4 minutes every time. But if it concerns only the layout (tweaking html), the templates are picked up by the binary on the fly and there is no need to recompile. The speed and memory usage (8.8 MB so far) are pleasing. Now I can update old apps and ship new ones.

UPDATE: With a simple update to Vapor 1.5.14, without changing any code, the site started using even less memory — 6.7–7.7 MB.

[↵] open page sajt-space-in-box.md
-rw-r--r-- 1.1K Dec 8, 2016 · B2818A9 · ~2 min

Benchmarks for Vapor 1.2.5

swift backend vapor ubuntu

About a month ago I launched benchmarks for Server side Swift frameworks. Yesterday I updated my project to the new version of Vapor: 1.2.5. Previous version I used was 1.1.11.

One of the most important updates in Vapor 1.2.x is that Vapor is now using a non-blocking server.

So today I decided to run a new benchmark for my project updated to Vapor 1.2 and results surprised me. It's not only faster than the 1.1.x version, it's now equal to Node.js results!

Vapor vs. Node.js

My server:

  • 2 GB RAM
  • 1 CPU Core
  • SSD
  • 125 MBPS Out
  • Ubuntu 16.10
  • CouchDB

Benchmark from other server was launched as:

wrk -t4 -c20 -d5m https://my_url

API just gets some data from CouchDB and returns it as JSON.

[↵] open page benchmarks-for-vapor-1-2-5.md
-rw-r--r-- 1.5K Nov 12, 2016 · A3940ED · ~2 min

Swift Backend with CouchDB: Kitura vs. Vapor vs. Node.js

swift backend vapor kitura ubuntu

I made a few test projects to implement an API for my simple app to run some benchmarks. It just makes 1 request to Database and returns JSON data.

All projects was executed on Linode VPS in London:

  • 2 GB RAM
  • 1 CPU Core
  • SSD
  • 125 MBPS Out
  • Ubuntu 16.10
  • MySQL and CouchDB with equal data (about 13k rows/documents)

Benchmarks was run on another, more powerful dedicated server in Germany using wrk:

wrk -t4 -c20 -d5m https://my_url

Results are very different from other benchmarks by Ryan Collins.

What did I try:

  • Node.js 7.0 + MySQL 5.7.16
  • Node.js 7.0 + CouchDB 2.0 (via node-couchdb)
  • Vapor 1.1.11 + CouchDB 2.0 (via HTTP)
  • Kitura 1.1.1 + CouchDB 2.0 (via Kitura-CouchDB)

Total requests

Requests per second

Average Latency

Results are very disappointing for me. Node.js was 50% faster than Swift. It looks like it's still not the right time to make backends on Swift right now, unless you don't expect high load and just want to write in Swift.

UPDATE: after about a month I ran another tests for the new version of Vapor (1.2.5) vs. Node.js and Vapor was very very fast. So now I'm very optimistic about using Swift as a backend.

[↵] open page swift-backend-with-couchdb-kitura-vs--vapor-vs-node-js.md
-rw-r--r-- 2.1K Nov 9, 2016 · 101665E · ~2 min

Vapor Framework for Swift Backend

swift vapor backend мечты о fullstack

Vapor logo

In the previous post I described my impressions of four Swift frameworks. More precisely, I wrote about three, and the fourth interested me, but I only got around to it now. In short — I am thrilled. It is wonderful.

First of all, the project has good documentation. Not perfect, but very good. With examples and learning materials. Everything in one place on the site — excellent.

First, the framework has a console tool that makes it very easy to create new projects, run existing ones, build them, deploy them to various services, and even create a Docker container. I think that is awesome, because whenever you start coding some project, even a test one, you immediately remember the various tools from the Node.js world and want to have something similar here.

Second, the set of libraries in the framework is excellent. There is an HTTP client, database wrappers, WebSocket support, templates; by default it offers a good project structure with everything organized into folders. Out of the box there is excellent support for JSON and data that can be converted both from JSON and into JSON. There is even a localization mechanism.

Third, I managed to make my own mini-client for CouchDB through plain HTTP requests, and it works. So far only for reading; I have not yet had time to check writing, but the fact that it all worked made me very happy.

Fourth, all requests are logged by default, roughly like in Express.js. So you set up routing and in the console you can see where requests are coming in, at least understanding what is happening. On top of that, the framework ships with a logging tool.

Fifth — my whole small test project compiled and ran on Linux without problems or crashes. It took a long time to compile, but it works, and that is great.

For memory usage it is worse than Perfect so far. Perfect started at 3.5 MB and grew to 5 MB. Vapor starts at 11 MB and grows to 14.9 MB. We will see what happens next; for now that is still twice less than Node.js.

For now I will probably stop at Vapor — in my opinion it is wonderful :)

[↵] open page frejmvork-vapor-dlya-bekenda-na-swift.md
-rw-r--r-- 9.2K Nov 6, 2016 · 9B2B8F3 · ~8 min

Server-Side Swift Frameworks

swift backend perfect kitura zewo vapor мечты о fullstack

A couple of months ago I came across a post about server-side Swift frameworks — a performance comparison of four Swift server frameworks against each other and against Node.js. Performance caught my attention. Judging by the results, Perfect came out on top. A month later the author posted another comparison of performance, but this time tested not on macOS, but on Linux. Perfect was in the lead again.

This weekend I decided to finally get my hands on it properly. Before that I took a quick look at the four frameworks being compared: Perfect, Kitura, Vapor and Zewo. I did not have many requirements for a framework; besides standard request routing and returning responses, I needed:

  • Templating support, so it can return not only JSON, but HTML too.
  • Support for network requests, since Foundation still has nothing ready for networking.
  • Preferably ready-made libraries for working with different databases.

Naturally, all of this needs to work under Linux.

[↵] open page frejmvork-perfect-dlya-servernogo-swift.md
makoni@arm1:~/blog$ cd .. // ↵ back to all posts