{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Session","type":"basic","slug":"session","excerpt":"","body":"Sessions allow data to be stored for an individual client using cookies.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"app.post(\\\"session\\\") { request in\\n    guard let name = request.data[\\\"name\\\"].string else {\\n        throw Abort.badRequest\\n    }\\n    request.session?[\\\"name\\\"] = name\\n\\n    return \\\"Session set\\\"\\n}\\n\\napp.get(\\\"session\\\") { request in\\n    guard let name = request.session?[\\\"name\\\"] else {\\n        return \\\"No session data\\\"\\n    }\\n\\n    return name\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nThe above code saves the `name` parameter posted to the POST `/session` route into the client's session.\n\nWhen the client then visits GET `/session` and supplies the cookie it received, the name will be returned.\n\nNote: Make sure `SessionMiddleware()` is enabled in your middleware.","updates":[],"order":10,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5768701b72cd4c0e000fad27","user":"57086f3d447c410e00221bd1","version":{"version":"0.12","version_clean":"0.12.0","codename":"Client Clyde","is_stable":false,"is_beta":true,"is_hidden":false,"is_deprecated":true,"categories":["5768701b72cd4c0e000fad19","5768701b72cd4c0e000fad1a","5768701b72cd4c0e000fad1b","5768701b72cd4c0e000fad1c"],"_id":"5768701b72cd4c0e000fad18","releaseDate":"2016-06-20T22:37:15.641Z","__v":1,"createdAt":"2016-06-20T22:37:15.641Z","project":"57086fe855a4690e005de407"},"createdAt":"2016-06-13T19:08:29.766Z","parentDoc":null,"__v":3,"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Guide","slug":"getting-started","order":1,"from_sync":false,"reference":false,"_id":"5768701b72cd4c0e000fad1a","createdAt":"2016-04-09T04:31:52.489Z","__v":0,"version":"5768701b72cd4c0e000fad18","project":"57086fe855a4690e005de407"},"githubsync":"","project":"57086fe855a4690e005de407"}
Sessions allow data to be stored for an individual client using cookies. [block:code] { "codes": [ { "code": "app.post(\"session\") { request in\n guard let name = request.data[\"name\"].string else {\n throw Abort.badRequest\n }\n request.session?[\"name\"] = name\n\n return \"Session set\"\n}\n\napp.get(\"session\") { request in\n guard let name = request.session?[\"name\"] else {\n return \"No session data\"\n }\n\n return name\n}", "language": "swift" } ] } [/block] The above code saves the `name` parameter posted to the POST `/session` route into the client's session. When the client then visits GET `/session` and supplies the cookie it received, the name will be returned. Note: Make sure `SessionMiddleware()` is enabled in your middleware.