I used the JS Fetch API with audio data using Clojure(Script)

I learned to use the JS Fetch API with audio data using ClojureScript. To send an audio file to the client, I learned the JS Fetch and FormData API (I’m unsure how else to send the audio data). The creators made Fetch promise-based, so this means understanding JS promises and the ClojureScript interop for it. I also learned about http headers. The fetch failed until I made the server (not the client) send an “Access-Control-Allow-Origin” header set to “localhost:3450” or “*”.

I thought depending on other ClojureScript libraries differed from Clojure until I noticed my typo

Leiningen uses Maven repos, usually Clojars, to pull in dependencies. With the right repos specified, lein install updates the pom.xml file, which causes Clojure to pull the files from the web needed to complete the requirement. I thought ClojureScript dependencies differed from Clojure, because I used lambdaisland/fetch, and it didn’t fly. After much research I double-checked the namespace name in the GitHub repo, and I saw it was lambdaisland.fetch. Changing it to this, the Figwheel compilation error disappeared, and my code worked again.

Clojure(Script) requires a certain file structure to build correctly

The Clojure/ClojureScript compiler takes directions from the pom.xml file, usually auto-generated with Leingingen, to see where to start and build everything from. It then uses these directions to traverse your file structure and then compile the Java bytecode/JavaScript.

Figwheel doesn't like the `lein install` approach

Figwheel errored me out with the lein install approach. I want to send http requests from the client, so I chose to use the JS Fetch API. Lambda Island made a fetch ClojureScript wrapper, so I (thought I) installed it, but on an attempted recompile, it says: “No such namespace: lambdaisland/fetch, could not locate lambdaisland_SLASH_fetch.cljs…”.

Understanding HTTP

I should learn the tools to manipulate HTTP payloads using the given control information. I see a lot of http libraries that’ll let me use the browser to interact with a server, but I didn’t understand HTTP itself. Now that I get that it’s “stuff” and “how to send and use the stuff”, I need to find robots that process the stuff and directions for using the stuff. I.e. I have some work to do learning Ring/Jetty for Clojure.

Clojure namespaces

In Clojure, you have boxes of code called namespaces, and there are ways of making Clojure communicate between the boxes. There are at least two boxes: clojure.core and your-project.core. If you have external libraries, more boxes will be added to the project. To talk between these boxes, use fully qualified symbols (your-project.other-namespace/func-name) or use refer to enable just using func-name. Now everywhere “boxes” are mentioned replace it with “namespaces”. Biblio:

CSS document flow

If I understand document flow and three properties’ effects on it, I can determine where elements will land. The display, float, and position properties manipulate elements from their default position in the “document flow”. display affects an elements response to box model properties: margin, border, and padding. It also decides whether elements can sit horizontal to it: “inline” yes, “block” no. float pulls things out of the normal flow and makes the normal things flow around it.

Mr. Goal

I posit a potentially better goal-achieving system. One thing people generally agree on is, “You get/become what you think”. I know that questions direct focus, so I repeat questions almost as a mantra. I tried to direct my foucs on the goal with the question, “What do I want”, but I’ve found this ineffective as the original goal fades, and the answer transforms to “Relax, watch Naruto, check Twitter, sleep…”, all short-term gratifications that do not progress me to the goal.

Learning to speak http

I think to speak with http servers and get their info, I need to know the anatomy of http requests. This means knowing how to populate a request with params, a body, and headers. Something that surprised me a while back is that an http request has multiple headers. Instead of anthropomorphizing the request, hydraize it. It’s a hydra, or a Cerberus: there are many headers. One header is “Authorization” while another is “Accept-Encoding”.

Coding requires thought, not effort. Thinking is questioning and answering. I'll use question-driven development to create the thinking necessary to code.

When coding, I’m gonna Q&A myself. Coding requires thought not effort. I read in Awaken the Giant Within [page number needed] that thinking is mostly the process of asking and answering questions. I recall a while back that I tried this, where I didn’t expect anything to get done until I first answer a question. Though it’s anecdotal, and I just what I recall from 4Clojure problem, the number of which I don’t remember, I remember it being effective.