<commit_before># 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:

```clojure
[stch-library/stateful "0.1.0"]
```

## API Documentation

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

Note: This library uses [stch.schema](https://github.com/stch-library/schema). Please refer to that project page for more information regarding type annotations and their meaning.

## How to use

Cookies

```clojure
(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/set "session-id" "12345"))

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

; Start some web server
(serve site)
```

Sessions

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

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

; or

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

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

; Start some web server
(run-server (site) {:port 9999})<commit_msg>Fixed readme.<commit_after># 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:

```clojure
[stch-library/stateful "0.1.0"]
```

## API Documentation

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

Note: This library uses [stch.schema](https://github.com/stch-library/schema). Please refer to that project page for more information regarding type annotations and their meaning.

## How to use

Cookies

```clojure
(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

```clojure
(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})
{'fraction_non_alphanumeric': 0.14509646302250803, 'fraction_numerical': 0.013665594855305467, 'mean_word_length': 3.705103969754253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1933967', 'n_tokens_mistral': 905, 'n_tokens_neox': 862, 'n_words': 244}