Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
 
 
 
 
 
 
 
 
 
 

README.md

stch.stateful

Stateful cookie and session middleware for Clojure Ring apps.

Based on code from https://github.com/noir-clojure/lib-noir.

Installation

Add the following to your project dependencies:

[stch-library/stateful "0.1.0"]

API Documentation

http://stch-library.github.io/stateful

Note: This library uses stch.schema. Please refer to that project page for more information regarding type annotations and their meaning.

How to use

Cookies

(ns my.ns
  (:require [stch.stateful.cookies :as cookie
             :refer [wrap-cookies-stateful]]))

(defn handler [req]
  (cookie/get "session-id"))

; or

(defn handler [req]
  (cookie/put! "session-id" "12345"))

(defn site []
  (-> handler
      wrap-cookies-stateful))

; Start some web server
(serve site)

Sessions

(ns my.ns
  (:require [stch.stateful.session :as session
             :refer [wrap-session-stateful]]))

(defn handler [req]
  (session/get "user"))

; or

(defn handler [req]
  (session/put! "user" {:name "Billy" :id 12345}))

(defn site []
  (-> handler
      wrap-session-stateful))

; Start some web server
(run-server (site) {:port 9999})

Combined

(defn site []
  (-> handler
      wrap-session-stateful
      wrap-cookies-stateful))

; Start some web server
(run-server (site) {:port 9999})

Unit-tests

Run "lein spec"

About

Stateful cookie and session middleware for Clojure Ring apps.

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.