1
votes

I'm just starting to pick up momentum with Haskell, and loving the abstractions I run into daily, such as lens.

I'm to a point where a REST API lens would be useful to work with, but before I spend hours finding it's not possible... is it?

The major problem I see is that I'm not directly accessing a data structure, but outputting a string which is requested (my lens syntax is probably wrong):

λ> over (user "robertplant") . set favoritesong

POST http://...com/api/user/robertplant/favoritesong
{
  ...
}

----

λ> over (user "robertplant") . view _1

GET http://...com/api/user/robertplant/favoritesong/123

I'm assuming that's at least an Applicative problem, or possibly needs an Monad?

I mean, I could imagine this lens satisfying the lens laws (in some sense... it's still a bit fuzzy to me), but I haven't seen yet that a lens has the hardware for putting out strings/other data structures like this.

Is this a journey worth pursuing?

1
Did you check wreq ?Sibi

1 Answers

0
votes

No, this doesn't have anything to do with lenses, unfortunately. Lenses are things that satisfy the lens laws

view l (set l v s) ≡ v
set l (view l s) s ≡ s
set l v' (set l v s) ≡ set l v' s

It's possible there's some clever thing you would write in Haskell to produce the outputs you're looking for, it just won't be related to this topic.