From b3123571082a8433f64e18e6064145c667241b4d Mon Sep 17 00:00:00 2001 From: Andrew Lees <32634907+Andrew-Lees11@users.noreply.github.com> Date: Thu, 13 Dec 2018 14:28:18 +0000 Subject: [PATCH 1/4] Docs: Add swift tag to README code --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63a3d51..df87d4c 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The router has a POST route that decodes a `User` instance from the request body The router has a GET route that reads a user id from the query parameters and decodes the instance of `User` that is in the session for that id. -``` +```swift public struct User: Codable { let id: String let name: String From 2e756bdee33c8eb5b1d685212c1963a0f9956555 Mon Sep 17 00:00:00 2001 From: Auto-Jazzy Date: Thu, 13 Dec 2018 15:54:27 +0000 Subject: [PATCH 2/4] [jazzy-doc] Documentation update --- docs/Classes.html | 2 +- docs/Classes/Session.html | 2 +- docs/Classes/SessionState.html | 50 +++++++++++++++++- docs/Enums.html | 2 +- docs/Enums/CookieParameter.html | 2 +- docs/Enums/StoreError.html | 2 +- docs/Extensions.html | 2 +- docs/Extensions/RouterRequest.html | 2 +- docs/Protocols.html | 2 +- docs/Protocols/Store.html | 2 +- docs/Protocols/TypeSafeSession.html | 2 +- docs/Structs.html | 2 +- docs/Structs/SessionCookie.html | 2 +- .../Contents/Resources/Documents/Classes.html | 2 +- .../Resources/Documents/Classes/Session.html | 2 +- .../Documents/Classes/SessionState.html | 50 +++++++++++++++++- .../Contents/Resources/Documents/Enums.html | 2 +- .../Documents/Enums/CookieParameter.html | 2 +- .../Resources/Documents/Enums/StoreError.html | 2 +- .../Resources/Documents/Extensions.html | 2 +- .../Documents/Extensions/RouterRequest.html | 2 +- .../Resources/Documents/Protocols.html | 2 +- .../Resources/Documents/Protocols/Store.html | 2 +- .../Documents/Protocols/TypeSafeSession.html | 2 +- .../Contents/Resources/Documents/Structs.html | 2 +- .../Documents/Structs/SessionCookie.html | 2 +- .../Contents/Resources/Documents/index.html | 36 ++++++++++++- .../Contents/Resources/Documents/search.json | 2 +- .../Contents/Resources/docSet.dsidx | Bin 12288 -> 28672 bytes docs/docsets/KituraSession.tgz | Bin 76294 -> 77500 bytes docs/index.html | 36 ++++++++++++- docs/search.json | 2 +- 32 files changed, 190 insertions(+), 34 deletions(-) diff --git a/docs/Classes.html b/docs/Classes.html index d70f0ae..7799875 100644 --- a/docs/Classes.html +++ b/docs/Classes.html @@ -182,7 +182,7 @@

Declaration

diff --git a/docs/Classes/Session.html b/docs/Classes/Session.html index a9a06d0..ad83562 100644 --- a/docs/Classes/Session.html +++ b/docs/Classes/Session.html @@ -272,7 +272,7 @@

Parameters

diff --git a/docs/Classes/SessionState.html b/docs/Classes/SessionState.html index d16775a..6498904 100644 --- a/docs/Classes/SessionState.html +++ b/docs/Classes/SessionState.html @@ -345,7 +345,7 @@

Parameters

-

Retrieve an entry from the session data.

+

Retrieve or store an entry from the session data.

@@ -378,6 +378,52 @@

Parameters

+
  • +
    + + + + subscript(_:) + +
    +
    +
    +
    +
    +
    +

    Retrieve or store a Codable entry from the session data.

    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public subscript<T: Codable>(key: String) -> T?
    + +
    +
    +
    +

    Parameters

    + + + + + + + +
    + + key + + +
    +

    The Codable key of the entry to retrieve/save.

    +
    +
    +
    +
    +
    +
  • @@ -386,7 +432,7 @@

    Parameters

    diff --git a/docs/Enums.html b/docs/Enums.html index 6852438..e2eac28 100644 --- a/docs/Enums.html +++ b/docs/Enums.html @@ -182,7 +182,7 @@

    Declaration

    diff --git a/docs/Enums/CookieParameter.html b/docs/Enums/CookieParameter.html index d15278e..ea058f3 100644 --- a/docs/Enums/CookieParameter.html +++ b/docs/Enums/CookieParameter.html @@ -249,7 +249,7 @@

    Declaration

    diff --git a/docs/Enums/StoreError.html b/docs/Enums/StoreError.html index 509ffea..b6aff0d 100644 --- a/docs/Enums/StoreError.html +++ b/docs/Enums/StoreError.html @@ -156,7 +156,7 @@

    Declaration

    diff --git a/docs/Extensions.html b/docs/Extensions.html index 5361ff1..61ea64c 100644 --- a/docs/Extensions.html +++ b/docs/Extensions.html @@ -151,7 +151,7 @@

    Declaration

    diff --git a/docs/Extensions/RouterRequest.html b/docs/Extensions/RouterRequest.html index 659aa94..40364a1 100644 --- a/docs/Extensions/RouterRequest.html +++ b/docs/Extensions/RouterRequest.html @@ -157,7 +157,7 @@

    Declaration

    diff --git a/docs/Protocols.html b/docs/Protocols.html index b0ad870..bb2f755 100644 --- a/docs/Protocols.html +++ b/docs/Protocols.html @@ -204,7 +204,7 @@

    Declaration

    diff --git a/docs/Protocols/Store.html b/docs/Protocols/Store.html index 830cc11..fc66eb2 100644 --- a/docs/Protocols/Store.html +++ b/docs/Protocols/Store.html @@ -373,7 +373,7 @@

    Parameters

    diff --git a/docs/Protocols/TypeSafeSession.html b/docs/Protocols/TypeSafeSession.html index 027205d..8143d5a 100644 --- a/docs/Protocols/TypeSafeSession.html +++ b/docs/Protocols/TypeSafeSession.html @@ -569,7 +569,7 @@

    Parameters

    diff --git a/docs/Structs.html b/docs/Structs.html index 51baeda..6ebb7be 100644 --- a/docs/Structs.html +++ b/docs/Structs.html @@ -155,7 +155,7 @@

    Declaration

    diff --git a/docs/Structs/SessionCookie.html b/docs/Structs/SessionCookie.html index 90c052e..8f0ebe5 100644 --- a/docs/Structs/SessionCookie.html +++ b/docs/Structs/SessionCookie.html @@ -275,7 +275,7 @@

    Parameters

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes.html index d70f0ae..7799875 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes.html @@ -182,7 +182,7 @@

    Declaration

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes/Session.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes/Session.html index a9a06d0..ad83562 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes/Session.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes/Session.html @@ -272,7 +272,7 @@

    Parameters

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes/SessionState.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes/SessionState.html index d16775a..6498904 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes/SessionState.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Classes/SessionState.html @@ -345,7 +345,7 @@

    Parameters

    -

    Retrieve an entry from the session data.

    +

    Retrieve or store an entry from the session data.

    @@ -378,6 +378,52 @@

    Parameters

    +
  • +
    + + + + subscript(_:) + +
    +
    +
    +
    +
    +
    +

    Retrieve or store a Codable entry from the session data.

    + +
    +
    +

    Declaration

    +
    +

    Swift

    +
    public subscript<T: Codable>(key: String) -> T?
    + +
    +
    +
    +

    Parameters

    + + + + + + + +
    + + key + + +
    +

    The Codable key of the entry to retrieve/save.

    +
    +
    +
    +
    +
    +
  • @@ -386,7 +432,7 @@

    Parameters

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums.html index 6852438..e2eac28 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums.html @@ -182,7 +182,7 @@

    Declaration

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums/CookieParameter.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums/CookieParameter.html index d15278e..ea058f3 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums/CookieParameter.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums/CookieParameter.html @@ -249,7 +249,7 @@

    Declaration

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums/StoreError.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums/StoreError.html index 509ffea..b6aff0d 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums/StoreError.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Enums/StoreError.html @@ -156,7 +156,7 @@

    Declaration

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Extensions.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Extensions.html index 5361ff1..61ea64c 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Extensions.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Extensions.html @@ -151,7 +151,7 @@

    Declaration

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Extensions/RouterRequest.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Extensions/RouterRequest.html index 659aa94..40364a1 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Extensions/RouterRequest.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Extensions/RouterRequest.html @@ -157,7 +157,7 @@

    Declaration

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols.html index b0ad870..bb2f755 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols.html @@ -204,7 +204,7 @@

    Declaration

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols/Store.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols/Store.html index 830cc11..fc66eb2 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols/Store.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols/Store.html @@ -373,7 +373,7 @@

    Parameters

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols/TypeSafeSession.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols/TypeSafeSession.html index 027205d..8143d5a 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols/TypeSafeSession.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Protocols/TypeSafeSession.html @@ -569,7 +569,7 @@

    Parameters

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Structs.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Structs.html index 51baeda..6ebb7be 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Structs.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Structs.html @@ -155,7 +155,7 @@

    Declaration

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Structs/SessionCookie.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Structs/SessionCookie.html index 90c052e..8f0ebe5 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Structs/SessionCookie.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/Structs/SessionCookie.html @@ -275,7 +275,7 @@

    Parameters

    diff --git a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/index.html b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/index.html index adf0219..fb53ebc 100644 --- a/docs/docsets/KituraSession.docset/Contents/Resources/Documents/index.html +++ b/docs/docsets/KituraSession.docset/Contents/Resources/Documents/index.html @@ -142,7 +142,7 @@

    Table of Contents

    Swift version

    -

    The latest version of Kitura-Session requires Swift 4.0. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.

    +

    The latest version of Kitura-Session requires Swift 4.0 or later. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.

    API

    In order to use the Session middleware, an instance of Session has to be created:

    @@ -174,6 +174,38 @@

    Example

    First an instance of RedisStore is created (see KituraSessionRedis for more information), then an instance of Session with the store as parameter is created, and finally it is connected to the desired path.

    +

    Codable Session Example

    + +

    The example below defines a User struct and a Router with the sessions middleware.
    +The router has a POST route that decodes a User instance from the request body + and stores it in the request session using the user’s id as the key.
    +The router has a GET route that reads a user id from the query parameters + and decodes the instance of User that is in the session for that id.

    +
    public struct User: Codable {
    +        let id: String
    +        let name: String
    +}
    +let router = Router()
    +router.all(middleware: Session(secret: "secret"))
    +router.post("/user") { request, response, next in
    +         let user = try request.read(as: User.self)
    +         request.session?[user.id] = user
    +         response.status(.created)
    +         response.send(user)
    +         next()
    +}
    +router.get("/user") { request, response, next in
    +         guard let userID = request.queryParameters["userid"] else {
    +            return try response.status(.notFound).end()
    +         }
    +         guard let user: User = request.session?[userID] else {
    +            return try response.status(.internalServerError).end()
    +         }
    +         response.status(.OK)
    +         response.send(user)
    +         next()
    +}
    +

    Plugins

    Swift version

    -

    The latest version of Kitura-Session requires Swift 4.0. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.

    +

    The latest version of Kitura-Session requires Swift 4.0 or later. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.

    API

    In order to use the Session middleware, an instance of Session has to be created:

    @@ -174,6 +174,38 @@

    Example

    First an instance of RedisStore is created (see KituraSessionRedis for more information), then an instance of Session with the store as parameter is created, and finally it is connected to the desired path.

    +

    Codable Session Example

    + +

    The example below defines a User struct and a Router with the sessions middleware.
    +The router has a POST route that decodes a User instance from the request body + and stores it in the request session using the user’s id as the key.
    +The router has a GET route that reads a user id from the query parameters + and decodes the instance of User that is in the session for that id.

    +
    public struct User: Codable {
    +        let id: String
    +        let name: String
    +}
    +let router = Router()
    +router.all(middleware: Session(secret: "secret"))
    +router.post("/user") { request, response, next in
    +         let user = try request.read(as: User.self)
    +         request.session?[user.id] = user
    +         response.status(.created)
    +         response.send(user)
    +         next()
    +}
    +router.get("/user") { request, response, next in
    +         guard let userID = request.queryParameters["userid"] else {
    +            return try response.status(.notFound).end()
    +         }
    +         guard let user: User = request.session?[userID] else {
    +            return try response.status(.internalServerError).end()
    +         }
    +         response.status(.OK)
    +         response.send(user)
    +         next()
    +}
    +

    Plugins