Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6003095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:04:22+00:00 2026-05-23T01:04:22+00:00

I’m trying to work out how to get sessions and flash working in Google

  • 0

I’m trying to work out how to get sessions and flash working in Google App Engine. Could someone provide a clear example using either Ring or Sandbar? I think I have sandbar working, specifically it doesn’t tell me that Var sandbar.stateful-session/sandbar-flash is unbound and when I dump the handler I get :flash and :session though I’m not certain if that is a sandbar session or a ring one. For completeness I will mention that I am using the latest versions of appengine-magic, ring, hiccup and sandbar. There do not appear to be any incompatibilities or issues.

So a clear example preferably with use of flash-put!, flash-get, session-put! and session-get.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:04:23+00:00Added an answer on May 23, 2026 at 1:04 am

    I don’t usually like answering my own questions, however in this case I’ll make an exception because:

    a) There isn’t a lot of easy to understand examples out there.

    b) It would be nice to have a quick working example for others to use.

    Note: appengine-magic is not required here, this will also work with normal ring sessions

    Code

    ;; Place in a file called session.clj in the example project
    (ns example.session
        "Works with the normal ring sessions 
         allowing you to use side-effects to manage them")
    
    (declare current-session)
    
    (defn wrap-session! [handler]
      (fn [request]
        (binding [current-session (atom (or (:session request) {}))]
          (let [response (handler request)]
            (assoc response :session @current-session)))))
    
    (defn session-get
      ([k] (session-get k nil))
      ([k default] (if (vector? k)
                     (get-in @current-session k)
                     (get @current-session k default))))
    
    (defn session-put!
      ([m]
         (swap! current-session (fn [a b] (merge a m)) m))
      ([k v]
         (swap! current-session (fn [a b] (merge a {k b})) v)))
    
    (defn session-pop! [k]
      (let [res (get @current-session k)]
        (swap! current-session (fn [a b] (dissoc a b)) k)
        res))
    
    (defn session-delete-key! [k]
      (swap! current-session (fn [a b] (dissoc a b)) k))
    
    (defn session-destroy! []
      (swap! current-session (constantly nil)))
    
    
    ;; Place in a file called core.clj in the example project
    (ns example.core
      (:use compojure.core
            [ring.middleware.keyword-params :only [wrap-keyword-params]]
            [ring.middleware.session :only [wrap-session]]
            [ring.middleware.session.cookie :only [cookie-store]]
            [example session])
      (:require [appengine-magic.core :as ae]))
    
    (declare current-session)
    
    (defroutes example-app-routes
      (GET "/" _
           (fn [req]
             (let [counter (session-get :counter 0)]
               {:status 200
                :headers {"Content-Type" "text/plain"}
                :body (str "started: " counter)})))
      (GET "/inc" _
           (fn [req]
             (let [counter (do 
                            (session-put! :counter (inc (session-get :counter 0)))
                            (session-get :counter))]
               {:status 200
                :headers {"Content-Type" "text/plain"}
                :body (str "incremented: " counter)}))))
    
    (def example-app-handler
      (-> #'example-app-routes
          wrap-keyword-params
          wrap-session!
          (wrap-session {:cookie-name "example-app-session"
                         :store (cookie-store)})))
    
    (ae/def-appengine-app example-app #'example-app-handler)
    

    How to use it

    Navigating to http://127.0.0.1:8080/inc increments the counter in the session and http://127.0.0.1:8080/ will display the value of counter in the session.

    wrap-session! is not required for sessions to work, just using

    (wrap-session {:cookie-name "example-app-session"
                         :store (cookie-store)})
    

    will give you working functional sessions. However I wanted to manage my sessions with side-effects and wrap-session! provides that functionality. To use flash like functionality, simply use session-put! to put a value into the session and then use session-pop! to remove it.

    Hope that’s helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.