Go to file
Caleb Kleveter 8b78db172e
Merge pull request #4 from skelpo/develop
Storage Subscripts and Request.storage Method
2018-05-09 16:25:09 -05:00
Sources Created Request.storage() method 2018-05-09 16:17:53 -05:00
Tests update 2018-04-16 14:39:39 -04:00
.gitignore update 2018-04-16 14:39:39 -04:00
Package.resolved Updated Vapor version to official release 2018-05-07 15:03:26 -05:00
Package.swift Updated Vapor version to official release 2018-05-07 15:03:26 -05:00
README.md Added docs to README 2018-04-20 12:07:45 -05:00

README.md

Vapor Request Storage

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

Installation

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.

Usage

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")