Fork me on GitHub

hey @guru01-have you seen the Clojure Cookbook? How does this code snippet strike you?


That code is all you need for a program that receives a request- like from a browser- and sends a response back. On top of that, a basic http server is just having your server send text responses that conform to the basics of the protocol. This is a gentle introduction to that protocol:


This person has gone through a similar exercise:, with posts on building an Echo Server, and an Agreeable Web Server. Maybe those are helpful?


Unfortunately the Clojure libraries that hide the underlying "Socket" abstraction in Java- which Java itself adopted, and which dates back more than 30 years- look up Berkeley Sockets if interested- are typically intended to serve more sophisticated use cases and programming styles, and may require a much greater cognitive lift.


Thanks a lot Jonah. That is very helpful. I did see that chapter in Clojure Cookbook - but not in detail. Let me go digging a bit more. All those links and info are very useful.


props to @jonahbenton on crushing it with the detailed help and code reviews


sure, thanks, happy to help @meow @guru01


I am converting a string map to keyword map and trying to massage some data as well as manipulate other. The :company value is set but when it reaches the function (accounts/account-create) it shows up nil.

user (-> (zipmap (map keyword (keys user)) (vals user))
                 (assoc :password salt)
                 (assoc :account_id (accounts/account-create (get user :company nil)))
Here is the map
{:first_name John, :last_name Quincy, :uid , :email , :password CYE8MGnf3Dyj, :company tester-mctestington, :account_id nil}


hey @ioneyed the user object is a string -> value map? so (get user :company nil) should be (get user "company" nil) ?


is your accounts/account-create function working correctly?


the accounts/account-create currently just prints the incoming company and it reports a nil


I tried to make your example self-contained, and this seems to work


(def user 
     {:first_name "John"
     :last_name "Quincy"
     :uid ""
     :email ""
     :password "CYE8MGnf3Dyj"
     :company "tester-mctestington"
     :account_id nil})

(-> (zipmap (map keyword (keys user)) (vals user))
    (assoc :password "hard-coded-salt")
    (assoc :account_id (str "company->account: " (get user :company nil))))


so if you swap accounts/account-create with identity you get the same result?


@jonahbenton: from my learning I thought the (-> operator would have applied the conversion from a string map to a keyword map before it got to my assoc :account_id so that it would be available via keywords


@jonahbenton: I was wrong and never thought to try that very simplistic attempt. It is being passed through now as it should.


@ioneyed- cool- one thing to still observe though about that code pattern. what that code is doing is "reassigning" a new map to a previously assigned local symbol. that will "work" but it's kind of anti-idiomatic, in that it's in the vein of mutability. so, one approach would be to populate a "str-user" symbol with the string map, and then assign a "kw-user" with the results of the (-> ) block.


I guess the better solution is to find a way to get it from compojure as a kw-map instead of str-map to begin with.


sure, though in web apps it's common and good practice to have an explicit data ingestion/validation/transformation step. Incoming data should be considered by default untrusted and at minimum in need of validation, subsequent to which it can be transformed into the model that suits the internal logic of the app


Hi, I’m trying to do remote CLJS figwheel stuff - I’m working on a remote server (in this case, a VM). I want my client code to connect to the websocket server on this VM. I’m using the re-frame todomvc example: . I added :figwheel { :websocket-host “VM ip addr” } under the :source-paths [“devsrc”] line, but i still get WebSocket connection to '' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED . I’m feeling pretty dumb at this point, am I missing something obvious? Thanks very much in advance for any help.


I was expecting my config change to change the URL in that error message...


i’m just running lein figwheel, fwiw, so i’m not sure if the lein profiles are playing into this?


welp, nevvvvvvvvver mind - found the actual place to put the config over here:


Does anyone know how to use void mutating java methods in clojure


I'm using the itext library(api?) and there's a .setData() method, but it only returns void, I can't seem to get the new object after .setData()


I tried doto, and the method does more than just change set one field, so I don't think set! applies here either


I've been experimenting with StringBuilder's .trimToSize() to test how to get a void method to work, how would I implement that for example?


hey @mark4carter doto is the right approach. can you share a non-working example?


(defn testSB
	(.toString (doto (StringBuilder. "   jump  ")


i think i read .trimtosize incorrectly


that might be the issue


ah, yeah. that doesn't do trim() on the visible part of the string, e.g. eliminate whitespace


let me try testing with something else, it could've been working how it was suppose to


ok yeah perfect


(defn testSB
	(.toString (doto (StringBuilder. "jump")
						(.setCharAt 1 (char 97))


works like it should