Originate / recouple

Declarative and type-safe API bridging. Write full-stack applications with ease.
MIT License
4 stars 1 forks source link

Extensible syntactic sugar for adding custom middleware #18

Closed sleexyz closed 6 years ago

sleexyz commented 6 years ago

Right now every piece of middleware sugar of Endpoint has to be hardcoded, i.e. .fragment is hardcoded to use the fragment middleware.

If we want to build an ecosystem, then we need to be able to have users easily extend the DSL with third-party middleware.


One solution is to have users be able to customize their "distribution" of safe-api. i.e. something like

const endpoint = SafeAPI()
  .use(thirdPartyMiddleware1)
  .use(thirdPartyMiddleware2)

const myEndpoint = endpoint()
  .thirdPartyMiddleware1()
  .thirdPartyMiddleware2()

In Servant, we don't have to do manual registering of third-party libraries because type-class instance resolution is done automatically at compile time. Since we don't have an automatically maintained registry of terms, we have to register extensions manually.

sleexyz commented 6 years ago

Closing for now, until we find we want to support

  1. 3rd party middleware
  2. direct fluent syntax to add 3rd party middleware