Coder Social home page Coder Social logo

Comments (6)

ikitommi avatar ikitommi commented on August 29, 2024 1

1.2.0-SNAPSHOT has the new api key :formats (: format is asserted away), here's the doc for for the key:

Comments welcome.

from compojure-api.

yogsototh avatar yogsototh commented on August 29, 2024

I actually wrote a middleware to generate csv format. And that would be very helpful.

Could you help me on another related subject? I have a middleware that transform the body of the ring response. I replace a map by a raw string. Unfortunately, the string is escaped. I don't really see how to prevent this transformation.

 (defn wrap-excel [handler]
    (fn [request]
      (let [new-request (update-in request [:meta :produces]
                                   #(concat % ["application/csv"]))
            response (handler new-request)]
        (if (= (get-in response [:headers "accept"]) "application/csv")
          (to-csv result)
          result))))

where to-csv do mostly an (update-in response [:body] map-to-csv-raw-string)

thanks

from compojure-api.

ikitommi avatar ikitommi commented on August 29, 2024

Hmm.. escaped? Not sure, but there is a serialization hint, allowing one to
return raw primitives, might help, see:

https://github.com/metosin/compojure-api/blob/master/test/compojure/api/middleware_test.clj

https://github.com/metosin/compojure-api/blob/master/src/compojure/api/meta.clj#L31-L33

does this help?
On 16 Dec 2014 11:19, "Yann Esposito" [email protected] wrote:

I actually wrote a middleware to generate csv format. And that would be
very helpful.

Could you help me on another related subject? I have a middleware that
transform the body of the ring response. I replace a map by a raw string.
Unfortunately, the string is escaped. I don't really see how to prevent
this transformation.

(defn wrap-excel [handler](fn [request]
%28let [new-request %28update-in request [:meta :produces]
#%28concat % ["application/csv"]%29%29
result %28handler new-request%29]
%28if %28= %28get-in request [:headers "accept"]) "application/csv")
(to-csv result)
result))))

where to-csv do mostly an (update-in (handler request) [:body]
map-to-csv-raw-string)

thanks


Reply to this email directly or view it on GitHub
#61 (comment)
.

from compojure-api.

yogsototh avatar yogsototh commented on August 29, 2024

Thanks, it helped me a lot! You rocks!

I had to write it like that:

(assoc response
            :compojure.api.meta/serializable? false
            :body (to-csv (:body res)))

from compojure-api.

ikitommi avatar ikitommi commented on August 29, 2024

we are about to release a new web-formats library soon. Will cover this and more.

from compojure-api.

ikitommi avatar ikitommi commented on August 29, 2024

´1.2.0-alpha2´

from compojure-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.