Swiftpack.co - Package - skelpo/vapor-request-storage

Vapor Request Storage

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


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

.package(url: "https://github.com/skelpo/vapor-request-storage.git", 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")


Stars: 6
Help us keep the lights on


Used By



0.4.0 - May 9, 2018

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 request.storage()
storage[key] // type `Any?`
storage[key] as Type? // type `Type?`
storage[key, as: Type.self] // type `Type?`

0.3.0 - May 7, 2018

A Series of Vaporish Events

It all started when we updated to the official Vapor 3.0 release...

0.2.0 - Apr 23, 2018

Safely Store Nothing

You can now store nil in a request:

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

When you access a nil value, pass in the base type to access and you will get an optional back.

try request.get("key", as String.self)
// nil

0.1.0 - Apr 19, 2018

All Systems Are ~Go~ Swift!

Storing data in a request is now made easy 🙂.

  1. Register the service:
try service.register(StorageProvider())
  1. Store data:
try request.set("key", to: value)
  1. Get data:
try request.get("key", as: Value.self)
let value: Value = try request.get("key")