servant icon indicating copy to clipboard operation
servant copied to clipboard

[RFC] Add TypeRep of api end-point to Foreign.Req.

Open fisx opened this issue 8 years ago • 6 comments

Not ready for merge, just interested in your thoughts on this. If you're short on time feel free to ignore or close.

Motivation: I want to write the api type of each end-point into a comment with the js client functions:

// :> Symbol * "r" (:> Symbol * "vote" (:> * * (Capture * "vote" PatchKey) (:> * * (ReqBody * (: * JSON []) IdeaVoteValue) (Verb StdMethod * POST 200 (: * JSON []) PatchVote))))
var postRVoteByVote = function(vote, body, onSuccess, onError)
{
  $.ajax(
    { url: '/r/vote/' + encodeURIComponent(vote) + ''
[...]

If you like this change, I will rebase this to current master, apply the changes to the other servant-js targets (currently there is only jquery), run the tests (should i add any for this?), and consider any other changes you may require.

Thanks!

fisx avatar Oct 31 '16 11:10 fisx

argh. just noticed this isn't working quite yet. anyway, interested in hearing how you like the idea! (-:

fisx avatar Oct 31 '16 11:10 fisx

[somewhat fixed it] [updated description above]

open problem: api types "only_end_point" :> Get '[JSON] Int has the default type (because it doesn't hit the :<|> instance), and AuthCombinator :> (route1 :<|> route2) doesn't mention the AuthCombinator in the types (because it hits the :<|> instance before it gets to that).

one solution would be to introduce an explicit type that steers update of reqApiType, and that we need to wrap each end-point in. this would have the benefit that the change to servant, servant-js would be minimal (only change the Req type), and the drawback that it would uglyfy the api types.

fisx avatar Oct 31 '16 12:10 fisx

@haskell-servant/maintainers can someone comment on this, servant-foreign code is quite foreign to me.

phadej avatar May 14 '17 13:05 phadej

If @fisx still wants this, I would not mind. Would this break packages depending on -foreign? If it would, we might want to involve the maintainers of those packages. @fisx would you mind leading that discussion, if you still want this patch to be merged?

alpmestan avatar May 15 '17 08:05 alpmestan

I don't need this right now, but I do not want it to go to waste. I'll try to get it rebased by the end of the week.

fisx avatar May 15 '17 09:05 fisx

@fisx Hi, any plans for this PR? Otherwise can I close it?

tchoutri avatar Nov 17 '21 14:11 tchoutri