How to make remote calls in CLJS
“I have my data ready to go. How do I get it to clojurescript?”
If you’ve been focused on backend work, it can be confusing when you get started on the frontend. One of the first steps is getting your data from the backend to the frontend.
cljs-http
is a nice library that makes it simple to get your data and move on to what you are really trying to accomplish.
Let’s say you have the following JSON on your server, located at /resources/clojure-langs.json
:
Making a simple remote call to the server only takes a few lines:
Here’s a live example, retrieving the static JSON from my server:
Simple get
and post
will get you a long way, and the docs provide great examples for the times you need more options.