Happstack, Yesod

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Happstack, Yesod

Corentin Dupont
Hi guys,
can I use servant with Happstack?
My app is currently built with Happstack, so it would be nice to handle the REST API also with it.
It seems there is only an alpha release now, right?
And what about Yesod? Is it supported?
Thanks,
Corentin

--
Reply | Threaded
Open this post in threaded view
|

Re: Happstack, Yesod

Julian Arni-2
With Yesod it's fairly easy - you can just use the `Raw` combinator

type MyAPI = ServantAPI :<|> "yesod" :> Raw

myServer :: Server MyAPI
myServer = servantServer :<|> toWaiApp ...

With Happstack, servant-happstack is an option (though then you would not be able to use the above method for Yesod, I believe).

Alternatively, you can just proxy the requests to the other frameworks, either by (a) having a proxy server that dispatches to either servant or the other framework based on route or headers or whatever it is, or (b) having one of the servant routes use a proxy (e.g., http-proxy [0]), and again use Raw. (a) is a pretty common technique generally.

[0] https://hackage.haskell.org/package/http-proxy

On Tue, May 10, 2016 at 2:47 PM, Corentin Dupont <[hidden email]> wrote:
Hi guys,
can I use servant with Happstack?
My app is currently built with Happstack, so it would be nice to handle the REST API also with it.
It seems there is only an alpha release now, right?
And what about Yesod? Is it supported?
Thanks,
Corentin

--

--
Reply | Threaded
Open this post in threaded view
|

Re: Happstack, Yesod

Corentin Dupont
Do you know when it will be released?


On Tue, May 10, 2016 at 3:18 PM, Julian Arni <[hidden email]> wrote:
With Yesod it's fairly easy - you can just use the `Raw` combinator

type MyAPI = ServantAPI :<|> "yesod" :> Raw

myServer :: Server MyAPI
myServer = servantServer :<|> toWaiApp ...

With Happstack, servant-happstack is an option (though then you would not be able to use the above method for Yesod, I believe).

Alternatively, you can just proxy the requests to the other frameworks, either by (a) having a proxy server that dispatches to either servant or the other framework based on route or headers or whatever it is, or (b) having one of the servant routes use a proxy (e.g., http-proxy [0]), and again use Raw. (a) is a pretty common technique generally.

[0] https://hackage.haskell.org/package/http-proxy

On Tue, May 10, 2016 at 2:47 PM, Corentin Dupont <[hidden email]> wrote:
Hi guys,
can I use servant with Happstack?
My app is currently built with Happstack, so it would be nice to handle the REST API also with it.
It seems there is only an alpha release now, right?
And what about Yesod? Is it supported?
Thanks,
Corentin

--


--
Reply | Threaded
Open this post in threaded view
|

Re: Happstack, Yesod

Julian Arni-2
Nope... the initial work was done by Jeremy Shaw, but someone would have to take over the task of merging it (which involves refactoring some of the common logic, and which relates to work that Greg Hale did with servant-snap). I don't know if anyone is working on that though.

On Tue, May 10, 2016 at 3:29 PM, Corentin Dupont <[hidden email]> wrote:
Do you know when it will be released?


On Tue, May 10, 2016 at 3:18 PM, Julian Arni <[hidden email]> wrote:
With Yesod it's fairly easy - you can just use the `Raw` combinator

type MyAPI = ServantAPI :<|> "yesod" :> Raw

myServer :: Server MyAPI
myServer = servantServer :<|> toWaiApp ...

With Happstack, servant-happstack is an option (though then you would not be able to use the above method for Yesod, I believe).

Alternatively, you can just proxy the requests to the other frameworks, either by (a) having a proxy server that dispatches to either servant or the other framework based on route or headers or whatever it is, or (b) having one of the servant routes use a proxy (e.g., http-proxy [0]), and again use Raw. (a) is a pretty common technique generally.

[0] https://hackage.haskell.org/package/http-proxy

On Tue, May 10, 2016 at 2:47 PM, Corentin Dupont <[hidden email]> wrote:
Hi guys,
can I use servant with Happstack?
My app is currently built with Happstack, so it would be nice to handle the REST API also with it.
It seems there is only an alpha release now, right?
And what about Yesod? Is it supported?
Thanks,
Corentin

--



--
Reply | Threaded
Open this post in threaded view
|

Re: Happstack, Yesod

Corentin Dupont

OK... I also use happstack-authenticate for authentication of my website. Can it be used with servant?
I'm not sure if happstack-authenticate can use the auth token in the HTTP header.

In general, how and where do you retrieve an auth token? Should I retrieve from happstack-authenticate?
I found this:
https://hackage.haskell.org/package/happstack-authenticate-2.3.4/docs/src/Happstack-Authenticate-Core.html#getToken
is this the token I should put in the header when making an API request?

On Tue, May 10, 2016 at 3:48 PM, Julian Arni <[hidden email]> wrote:
Nope... the initial work was done by Jeremy Shaw, but someone would have to take over the task of merging it (which involves refactoring some of the common logic, and which relates to work that Greg Hale did with servant-snap). I don't know if anyone is working on that though.

On Tue, May 10, 2016 at 3:29 PM, Corentin Dupont <[hidden email]> wrote:
Do you know when it will be released?


On Tue, May 10, 2016 at 3:18 PM, Julian Arni <[hidden email]> wrote:
With Yesod it's fairly easy - you can just use the `Raw` combinator

type MyAPI = ServantAPI :<|> "yesod" :> Raw

myServer :: Server MyAPI
myServer = servantServer :<|> toWaiApp ...

With Happstack, servant-happstack is an option (though then you would not be able to use the above method for Yesod, I believe).

Alternatively, you can just proxy the requests to the other frameworks, either by (a) having a proxy server that dispatches to either servant or the other framework based on route or headers or whatever it is, or (b) having one of the servant routes use a proxy (e.g., http-proxy [0]), and again use Raw. (a) is a pretty common technique generally.

[0] https://hackage.haskell.org/package/http-proxy

On Tue, May 10, 2016 at 2:47 PM, Corentin Dupont <[hidden email]> wrote:
Hi guys,
can I use servant with Happstack?
My app is currently built with Happstack, so it would be nice to handle the REST API also with it.
It seems there is only an alpha release now, right?
And what about Yesod? Is it supported?
Thanks,
Corentin

--




--
Reply | Threaded
Open this post in threaded view
|

Re: Happstack, Yesod

Corentin Dupont
Hi again guys,
is there some resource for using authentication with Yesod and Servant?
Thanks

On Tue, May 10, 2016 at 8:21 PM, Corentin Dupont <[hidden email]> wrote:

OK... I also use happstack-authenticate for authentication of my website. Can it be used with servant?
I'm not sure if happstack-authenticate can use the auth token in the HTTP header.

In general, how and where do you retrieve an auth token? Should I retrieve from happstack-authenticate?
I found this:
https://hackage.haskell.org/package/happstack-authenticate-2.3.4/docs/src/Happstack-Authenticate-Core.html#getToken
is this the token I should put in the header when making an API request?

On Tue, May 10, 2016 at 3:48 PM, Julian Arni <[hidden email]> wrote:
Nope... the initial work was done by Jeremy Shaw, but someone would have to take over the task of merging it (which involves refactoring some of the common logic, and which relates to work that Greg Hale did with servant-snap). I don't know if anyone is working on that though.

On Tue, May 10, 2016 at 3:29 PM, Corentin Dupont <[hidden email]> wrote:
Do you know when it will be released?


On Tue, May 10, 2016 at 3:18 PM, Julian Arni <[hidden email]> wrote:
With Yesod it's fairly easy - you can just use the `Raw` combinator

type MyAPI = ServantAPI :<|> "yesod" :> Raw

myServer :: Server MyAPI
myServer = servantServer :<|> toWaiApp ...

With Happstack, servant-happstack is an option (though then you would not be able to use the above method for Yesod, I believe).

Alternatively, you can just proxy the requests to the other frameworks, either by (a) having a proxy server that dispatches to either servant or the other framework based on route or headers or whatever it is, or (b) having one of the servant routes use a proxy (e.g., http-proxy [0]), and again use Raw. (a) is a pretty common technique generally.

[0] https://hackage.haskell.org/package/http-proxy

On Tue, May 10, 2016 at 2:47 PM, Corentin Dupont <[hidden email]> wrote:
Hi guys,
can I use servant with Happstack?
My app is currently built with Happstack, so it would be nice to handle the REST API also with it.
It seems there is only an alpha release now, right?
And what about Yesod? Is it supported?
Thanks,
Corentin

--





--
Reply | Threaded
Open this post in threaded view
|

Re: Happstack, Yesod

Julian Arni-2
On Thu, May 12, 2016 at 8:18 PM, Corentin Dupont <[hidden email]> wrote:
Hi again guys,
is there some resource for using authentication with Yesod and Servant?

I don't think anyone has blogged about it. But how are those two connected? If in the same Application, you can use authentication/session Middleware, and it'll just work for both.
 
Thanks

On Tue, May 10, 2016 at 8:21 PM, Corentin Dupont <[hidden email]> wrote:

OK... I also use happstack-authenticate for authentication of my website. Can it be used with servant?
I'm not sure if happstack-authenticate can use the auth token in the HTTP header.

In general, how and where do you retrieve an auth token? Should I retrieve from happstack-authenticate?
I found this:
https://hackage.haskell.org/package/happstack-authenticate-2.3.4/docs/src/Happstack-Authenticate-Core.html#getToken
is this the token I should put in the header when making an API request?

On Tue, May 10, 2016 at 3:48 PM, Julian Arni <[hidden email]> wrote:
Nope... the initial work was done by Jeremy Shaw, but someone would have to take over the task of merging it (which involves refactoring some of the common logic, and which relates to work that Greg Hale did with servant-snap). I don't know if anyone is working on that though.

On Tue, May 10, 2016 at 3:29 PM, Corentin Dupont <[hidden email]> wrote:
Do you know when it will be released?


On Tue, May 10, 2016 at 3:18 PM, Julian Arni <[hidden email]> wrote:
With Yesod it's fairly easy - you can just use the `Raw` combinator

type MyAPI = ServantAPI :<|> "yesod" :> Raw

myServer :: Server MyAPI
myServer = servantServer :<|> toWaiApp ...

With Happstack, servant-happstack is an option (though then you would not be able to use the above method for Yesod, I believe).

Alternatively, you can just proxy the requests to the other frameworks, either by (a) having a proxy server that dispatches to either servant or the other framework based on route or headers or whatever it is, or (b) having one of the servant routes use a proxy (e.g., http-proxy [0]), and again use Raw. (a) is a pretty common technique generally.

[0] https://hackage.haskell.org/package/http-proxy

On Tue, May 10, 2016 at 2:47 PM, Corentin Dupont <[hidden email]> wrote:
Hi guys,
can I use servant with Happstack?
My app is currently built with Happstack, so it would be nice to handle the REST API also with it.
It seems there is only an alpha release now, right?
And what about Yesod? Is it supported?
Thanks,
Corentin

--






--
Reply | Threaded
Open this post in threaded view
|

Re: Happstack, Yesod

Yann Esposito
Actually I'm using a Yesod application which use their plugin system for authentication.
Here is some working code:

~~~~
import Data.CaseInsensitive (CI)

identityHeaderName :: CI ByteString
identityHeaderName = "Yesod-Identity"

addQueryId :: Maybe ByteString -> W.Request -> W.Request
addQueryId identity req =
  let f = maybe id (\x hs -> (identityHeaderName,x):hs) identity
  in req {W.requestHeaders = f (W.requestHeaders req)}

removeIdentityQuery :: W.Request -> W.Request
removeIdentityQuery req = req {
  W.requestHeaders = filter ((/= identityHeaderName) . fst)
                            (W.requestHeaders req)
  }

addIdentity :: Maybe ByteString -> Middleware
addIdentity identity app req sendResp =
  let req' = removeIdentityQuery req
      req'' = addQueryId identity req'
  in
    app req'' sendResp

addIdentity :: Maybe ByteString -> Middleware
addIdentity identity app req sendResp =
  let req' = removeIdentityQuery req
      req'' = addQueryId identity req'
  in
    app req'' sendResp

followToApp :: Handler TypedContent
followToApp = do
  app <- getYesod
  auth <- maybeAuth
  let identity = case auth of
                      Just (Entity _ u) -> Just (encodeUtf8 (userIdent u))
                      Nothing -> Nothing
  print identity
  sendWaiApplication (addIdentity identity (appREST app))

getHomeR :: Texts -> Handler TypedContent
getHomeR _ = followToApp

postHomeR :: Texts -> Handler TypedContent
postHomeR _ = followToApp
~~~~

and I had to put this in config/routes:

~~~
!/*Texts HomeR GET POST
~~~

The `appREST` is the WAI application returned by Servant that I initialise in Foundation.hs.
I added `appREST` field of type Application in the App record.

On Friday, May 13, 2016 at 1:18:54 PM UTC+2, Julian Arni wrote:
On Thu, May 12, 2016 at 8:18 PM, Corentin Dupont <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="h8oID-oHCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">corenti...@...> wrote:
Hi again guys,
is there some resource for using authentication with Yesod and Servant?

I don't think anyone has blogged about it. But how are those two connected? If in the same Application, you can use authentication/session Middleware, and it'll just work for both.
 
Thanks

On Tue, May 10, 2016 at 8:21 PM, Corentin Dupont <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="h8oID-oHCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">corenti...@...> wrote:

OK... I also use happstack-authenticate for authentication of my website. Can it be used with servant?
I'm not sure if happstack-authenticate can use the auth token in the HTTP header.

In general, how and where do you retrieve an auth token? Should I retrieve from happstack-authenticate?
I found this:
<a href="https://hackage.haskell.org/package/happstack-authenticate-2.3.4/docs/src/Happstack-Authenticate-Core.html#getToken" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fhappstack-authenticate-2.3.4%2Fdocs%2Fsrc%2FHappstack-Authenticate-Core.html%23getToken\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFPCofG6sSPty3l7eCy0PUixhZS9g&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fhappstack-authenticate-2.3.4%2Fdocs%2Fsrc%2FHappstack-Authenticate-Core.html%23getToken\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFPCofG6sSPty3l7eCy0PUixhZS9g&#39;;return true;">https://hackage.haskell.org/package/happstack-authenticate-2.3.4/docs/src/Happstack-Authenticate-Core.html#getToken
is this the token I should put in the header when making an API request?

On Tue, May 10, 2016 at 3:48 PM, Julian Arni <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="h8oID-oHCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jka...@...> wrote:
Nope... the initial work was done by Jeremy Shaw, but someone would have to take over the task of merging it (which involves refactoring some of the common logic, and which relates to work that Greg Hale did with servant-snap). I don't know if anyone is working on that though.

On Tue, May 10, 2016 at 3:29 PM, Corentin Dupont <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="h8oID-oHCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">corenti...@...> wrote:
Thanks.
I saw servant-happstack here:
<a href="https://github.com/haskell-servant/servant/tree/servercommon/servant-happstack" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fhaskell-servant%2Fservant%2Ftree%2Fservercommon%2Fservant-happstack\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFNs0RUtbNCjynur6U0v-1qpq4KrA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fhaskell-servant%2Fservant%2Ftree%2Fservercommon%2Fservant-happstack\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFNs0RUtbNCjynur6U0v-1qpq4KrA&#39;;return true;">https://github.com/haskell-servant/servant/tree/servercommon/servant-happstack

Do you know when it will be released?


On Tue, May 10, 2016 at 3:18 PM, Julian Arni <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="h8oID-oHCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jka...@...> wrote:
With Yesod it's fairly easy - you can just use the `Raw` combinator

type MyAPI = ServantAPI :<|> "yesod" :> Raw

myServer :: Server MyAPI
myServer = servantServer :<|> toWaiApp ...

With Happstack, servant-happstack is an option (though then you would not be able to use the above method for Yesod, I believe).

Alternatively, you can just proxy the requests to the other frameworks, either by (a) having a proxy server that dispatches to either servant or the other framework based on route or headers or whatever it is, or (b) having one of the servant routes use a proxy (e.g., http-proxy [0]), and again use Raw. (a) is a pretty common technique generally.

[0] <a href="https://hackage.haskell.org/package/http-proxy" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fhttp-proxy\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFjD2qCzt2NimOed5FUZ5goRddzCw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fhackage.haskell.org%2Fpackage%2Fhttp-proxy\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFjD2qCzt2NimOed5FUZ5goRddzCw&#39;;return true;">https://hackage.haskell.org/package/http-proxy

On Tue, May 10, 2016 at 2:47 PM, Corentin Dupont <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="h8oID-oHCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">corenti...@...> wrote:
Hi guys,
can I use servant with Happstack?
My app is currently built with Happstack, so it would be nice to handle the REST API also with it.
It seems there is only an alpha release now, right?
And what about Yesod? Is it supported?
Thanks,
Corentin

--






--