Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NamedRoutes not implemented #40

Open
immae opened this issue Jun 22, 2023 · 4 comments
Open

NamedRoutes not implemented #40

immae opened this issue Jun 22, 2023 · 4 comments

Comments

@immae
Copy link

immae commented Jun 22, 2023

I’m trying to use the servant-checked-exceptions package with NamedRoutes. But I want to add the "Throws" at the top of the api, for instance:

data ApiFoo mode = ApiFoo
  {
    get :: mode :- Get '[JSON] Foo
   , post :: mode :- "new" :> ReqBody '[JSON] Foo :> Post '[JSON] ()
  }

data ApiStore mode = ApiStore
  {
    fooStore :: mode :- "foo" :> NamedRoutes ApiFoo
  , barStore :: mode :- "bar" :> NamedRoutes ApiBar

  }

type API = Throws StoreError :> "store" :> NamedRoutes ApiStore

But Throws is not able to traverse NamedRoutes types. I tried to implement a HasServer (Throwing '[e] :> NamedRoutes api) instance, but I seem unable to do it correctly (I tried to find other packages that implement a similar instance too to use as example, in vain). I’d appreciate help for implementing that.

Thanks!

@cdepillabout
Copy link
Owner

I've never actually used NamedRoutes before.

Could you upload a branch with the (non-working) code you currently have?

@immae
Copy link
Author

immae commented Jun 22, 2023

Thanks for your consideration. I took a bit of time to extract what I tried to do from local specificities. You’ll find the attempt here: https://github.com/immae/servant-checked-exceptions/tree/wip-named-routes

I added an "example" file /Movies.hs (which I use in the repl to play around), using the NamedRoutes example from Servant themselves (https://docs.servant.dev/en/inserting_doc_namedroutes/cookbook/namedRoutes/NamedRoutes.html ), and tried to "build" an api that can Throw from it and add the needed instances. Somehow I got a bit further than what I achieved in my own local work (I have a feeling that the AsEnveloppedServerT is kind of necessary), but I’m still not there.

Sorry that I cannot help more, It’s easy to get lost in all the Servant types.

Hope this sketch helps a bit!

@cdepillabout
Copy link
Owner

I took a look at this, but I don't think I'll have time to grok exactly how Generic is being used in the implementation of NamedRoutes, at least to the point where I can use it to implement support here in servant-checked-exceptions.

For anyone else interested, here is the servant-server code that deals with NamedRoutes:

https://hackage.haskell.org/package/servant-server-0.20/docs/src/Servant.Server.Internal.html#AsServerT

I'd be happy to merge a PR adding support for NamedRoutes here in servant-checked-exceptions if someone is able to figure everything out.

@immae
Copy link
Author

immae commented Jun 28, 2023

Thank you for taking the time to look at it.

I didn’t make progress so far (further than what I published already in the branch)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants