What's New



Subscribe Below

Storage now has subscript methods for accessing it's values should you decide to use the request's private storage instance instead of the .get and .set methods.

Request has .storage method to get it's private storage instance instead of having to fetch it manually.

let storage = try
storage[key] // type `Any?`
storage[key] as Type? // type `Type?`
storage[key, as: Type.self] // type `Type?`

Vapor Request Storage

This package works as a replacement for which was available in Vapor 1 & 2.


Add the package declaration to your project's manifest dependencies array:

.package(url: "", from: "0.1.0")

Then add the VaporRequestStorage to the dependencies array of any target you want access to it in.

Complete the installation by running vapor update or swift package update from the command-line.


In the configure.swift file, import VaporRequestStorage. Then register the provider with the services object passed into the configure(_:_:_:) function:

try service.register(StorageProvider())

You can now use the Storage service and a privateContainer to store data in a request.

To set a value, there is a request.set(_:to:) method:

try request.set("key", to: value)

To get the value later, use the request.get(_:as:) method:

try request.get("key", as: Value.self)

The second parameter of the get method has a default value of Stored.self, which means if you specify the return type somewhere else, you can skip passing that value in:

let value: Value = try request.get("key")


  • Swift Tools 4.0.0
View More Packages from this Author


Last updated: Fri Mar 17 2023 00:23:18 GMT-0500 (GMT-05:00)