Fork me on GitHub
#beginners
<
2019-07-27
>
Anik Chowhdury08:07:16

hi! I'm noob to clojure. I am using luminus for creating webserver for routing. I want to pass data using route like the url is "http://localhost:3600/test?data=“xxx” " want to get the data which will be dynamically changed.

(defn testing-func
  [{:keys [path-params query-params body-params]}]
  {:status 200
   :body   (str "path params: " path-params
             "\nquery params: " query-params
             "\nbody params: " body-params)}
  (prn "id details:" query-params))


(defroutes home-routes
 
  (POST "/test/:id" [id] (testing-func id))

)
here is my code. I know there is lots of mistakes. Can anyone tell me how to get data from routes? Thanks in advance!

Crispin09:07:14

your route would be (POST "/test/:id" request (testing-func request))

Crispin09:07:41

then if you change your testing func to

Crispin09:07:16

(defn testing-func [{:keys [path-params query-params body-params] :as request}] ... )

Crispin09:07:35

and then in the body of the function print out the request

Crispin09:07:57

(clojure.pprint/pprint request)

Crispin09:07:16

now hit it with some POST requests and have a look whats inside the request hashmap

Crispin09:07:46

you should find all kinds of goodies in there

Crispin09:07:03

if you have anymore queries try #luminus

Crispin09:07:03

oh and be aware that doesn't match the url you posted as tryng

Crispin09:07:53

so make sure your POST requests go to the right URL

Crispin09:07:12

to match the URL you are using it would be (POST "/test" request (testing-func request))

Crispin09:07:30

also ? are get parameters not post

David Pham09:07:03

I have been coding with Clojure since a few years (professionally since a 1 year thanks to CLJS). I read this article https://purelyfunctional.tv/guide/5-hurdles-of-hirability/ from Eric Normand and I wondered what it meant to be coding in the functional paradigm? I use pure function, function composition, immutable data (except for atoms) and focus on declaration more than imperative. Do I miss anything in my toolbox?

David Pham09:07:51

(I am really happy to code with Clojure that being said).

dmaiocchi09:07:53

Unless I'm not missing some things 😁 :thinking_face:

dmaiocchi09:07:35

There is Also the club of lispers, but the group of functional is that imho

David Pham09:07:40

@darioszr I can’t read the first part of your message haha

dmaiocchi09:07:16

Aha sorry, let me rewrite it I think I had some typos

dmaiocchi09:07:14

1st part: IO handling and states, composition, declaritive code and data thinking is the key to be in the functional club

dmaiocchi09:07:37

So IMHO you are already in the club, welcom:clj:

dmaiocchi09:07:47

For sure you can improve things, but to me with also immutable data, this all are key factors to be in functional paradigm. But maybe others could express their pov

dmaiocchi09:07:08

The functional thinking is imho when you think how to manipulate your data in pipelines or transducers and immutability is also something that Oop people dont get it

👍 8
David Pham09:07:57

Ok, by that definition I am for sure a FP member lol. I still can’t understand why python does not have -> in their language

David Pham09:07:09

Thanks a lot. I really thought I was missing something.

dmaiocchi10:07:11

Yw, but IMHO we are speaking on the functional low level of things. To me the functional level can be also improved, like how is à functional system, how components interact in a functional way. Eg understanding persistent data structures, message passing applications this is imho what is interesting on more larger view.

dmaiocchi11:07:57

Just citing 2 examples..

P69611:07:11

How to achieve this with Clojure? Suppose I am getting a string from console. “A B C”. Now I am splitting this string using split function. And trying map each of the sub string to a particular key in map. {:first-name A , :last-name B , :middxlename C}. Now, if I get another console input. I want to append that entry into the existing map. If second console input is “D E F”. Then, resulting map I am expecting is :- { {:first-name A , :last-name B , :middlename C} {:first-name D , :last-name E , :middlename F} } I’have just started getting into Clojure. Any help would be great.

jaihindhreddy11:07:10

You can right a fn that parses the string into a map like this:

(defn parse [s]
 (->> (clojure.string/split s #" ")
      (zipmap [:first :last :middle])))

jaihindhreddy11:07:45

(parse "A B C") will return {:first "A", :last "B", :middle "C"}

jaihindhreddy11:07:23

You can then just maintain a vector and use conj to append to it for each input received.

jaihindhreddy11:07:10

But I feel like I misunderstood what you want? Does this make sense @parth.12282?

David Pham11:07:03

How I see: it is you can a mutable state but the functions that processes the input should be pure

David Pham11:07:26

(From my experience of re-frame)

David Pham11:07:27

(The funniest piece of documentation)

P69611:07:00

@jaihindhreddy vector wont let me mutate the state.If i am doing conj with another map as input. I need to store that output somewhere. (As per my limited knowledge)

4
jaihindhreddy12:07:27

Is what your working on an interactive cli in Clojure?

P69612:07:29

i am parsing console commands one after another

David Pham11:07:25

Save the state in a global atom

jaihindhreddy12:07:31

yup, you'd use an atom. I don't know if the app at hand is an interactive thing where user enters these string, which is when atoms would be right, or if it is possible to get all the inputs at the same time in which case its a simple (map parse strs)

David Pham13:07:59

@darioszr Do you know where I could read about functional systems? What are the guidelines? My understanding is we should apply the same principle as in low level: avoid states, (pure systems? Same input yields the same output)?

dmaiocchi13:07:36

The book clojure Applied from @alexmiller discuss it in some chapters. A part of that book, i recommend you the talk of rich https://m.youtube.com/watch?v=ROor6_NGIWU&amp;feature=youtu.be Unfortunately I think our industry isnt that mature, to build f systems' I think building functional systems is our challenge for nowadays. I mean building functional style programs, is for developers sanity of mind 😁

dmaiocchi13:07:09

But we should not stop on the micro level, we should extend this in the system level, e.g persistent data structures, channels etc. I'm just starting researching the topic. But this is imho what business people, Users, care 😁

dmaiocchi13:07:39

A part of that, we don't have like functional architecture books yet, I don't know if somebody has such book feel free to share

dmaiocchi13:07:05

Recently I have bought this book

dmaiocchi13:07:02

But they are free online. I think it is a cool book, discussing architectures of OOp mostly software but one can extrapolate some principles... There is also the Haskell compiler there afaik

dmaiocchi13:07:55

But it is not written In Haskell for sure 😁

schmee13:07:20

@darioszr I think the book Domain-driven design is very interesting for functional programming, it’s not really about any specific programming paradigm but the books talks about a lot of concepts which go very well together with functional programming

dmaiocchi13:07:05

Right which do you mean? Because there are 2 out there

dmaiocchi13:07:29

I have heard about that but there are severals

dmaiocchi13:07:27

I might read it, I have heard good things about it

schmee13:07:17

it’s worth your while! 🙂 I especially like that it’s not preachy like a lot of other software books, instead it’s like “use this when you think that it makes sense, if it doesn’t, do something else”

clj 4
Crispin14:07:50

change :n -> :1

dmaiocchi19:07:22

Hi all, I'm searching in the web on a document between data serialization formats différence

dmaiocchi19:07:14

I know that Rich and Stuart talked a little on the subjects. If anyone know a good line where it is somehow explained in deep, feel free to share clj lambdalove

dmaiocchi19:07:58

(I'm referring to talk of language of system video) where data formats are described

jaihindhreddy09:07:10

Check out Stuart Halloway's talk on Fressian.

jaihindhreddy09:07:26

I'm interested in this too. Will post in this thread when I find something interesting.

clj 4
dmaiocchi09:07:31

Do you have a link for that talk?

dmaiocchi17:07:20

About system found out also this great talk, it talk about great things (link: https://youtu.be/Tb823aqgX_0) http://youtu.be/Tb823aqgX_0