Fork me on GitHub
#re-frame
<
2021-07-23
>
Elias Elfarri17:07:10

If i send some paramtrrs into a rest API with a GET request using reg-event-fx with reframe, and i wqnt the backend to access the data through a compojure set up, is it enough to do the following? `(defroutes app (GET “/“ [a b] (response (+ a b)))` Assuming that a and b are data that are sent into the restAPI and that everything todo with ring middleware and json wrapping is taken care of? I guess this is more of a compojure question but idk where to post it.

emccue17:07:42

Take like 10 steps back. Your get handler there needs to handle the request in some way. When you say (GET "/" [a b] ...) where does it take the info from in the request to get a and b

emccue17:07:48

can it do that?

emccue17:07:46

once you can call your api with curl, then you can shift to figuring out how to construct a request from the frontend

Elias Elfarri17:07:27

I guess i wasnt being precise enough, i am wondering more about how to access the json data with compojure. If i know it has a format {”a”: 1}, how do you access that data with destructuring?

Elias Elfarri18:07:34

Is it as easy as using a vector?

emccue20:07:25

sorry, twas busy

emccue20:07:34

if you have json decoded into a map

emccue20:07:36

if its like this

emccue20:07:45

{:a 1 :b 2}

emccue20:07:50

you can destructure it like this

emccue20:07:03

(let [{:keys [a b]} json] ...)

emccue20:07:05

if its like this

emccue20:07:11

{"a" 1 "b" 2}

emccue20:07:18

you can destructure it like this

emccue20:07:31

(let [{:strs [a b]} json] ...)

AJ Jaro01:07:38

@U027C7611DF with compojure you'll usually be working with the request object on the route. So it's not that much different from what @U3JH98J4R mentioned but just slightly where you'd have to get some values out of the body of the request structure in order to see the map you passed into the API

Elias Elfarri17:07:58

Also i assume that frontend uses the same route