gcanti / fp-ts-routing

A type-safe bidirectional routing library for TypeScript

Home Page:https://gcanti.github.io/fp-ts-routing/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose the Routing Algebra

sledorze opened this issue · comments

This is a direct follow up of #25

It may be a useful general pattern that can be used in other libraries (eg io-ts).

@gcanti may you accept a PR?

@sledorze no, such a Routing language is arbitrary, it could be defined as

interface Routing2<F> {
  end: MatchSyntax<F, {}>
  str: <K extends string>(k: K) => MatchSyntax<F, { [_ in K]: string }>
  int: <K extends string>(k: K) => MatchSyntax<F, { [_ in K]: number }>
  lit: (s: string) => MatchSyntax<F, {}>
  query: <A extends object>(type: t.Type<A, Query>) => MatchSyntax<F, A>
}

or you could even compile a subset of swagger to Match.

A specific Routing language implemented in your codebase is fine if it fits your needs, but should be external to the library.

Having played a bit yesterday and today with several integration for a io-ts derived lang, I fully understand that now (had to accommodate the lang to the actual API needs rather than mimicking the API of to a particular derivation).
That was a bad and short sighted solution.