Skip to main content
On this pageFunctions

Route

Functions

int

functionsource
/**
 * Creates a parser that captures a URL segment as a named integer field.
 * 
 * Fails if the segment is not a valid integer.
 */
<K extends string>(name: K): Biparser<Record<K, number>>

literal

functionsource
/** Creates a parser that matches an exact URL path segment. */
(segment: string): Biparser<{}>

oneOf

functionsource
/**
 * Combines multiple parsers, trying each in order until one succeeds.
 * 
 * Returns a `Parser` (parse-only) since the union of different route
 * shapes cannot provide a single unified print function.
 */
<Parsers extends readonly Array<ParserInput>>(parsers: Parsers): Parser<InferParsed<Parsers[number]>>

param

functionsource
/** Creates a parser for a dynamic URL segment with custom parse and print functions. */
<A>(
  label: string,
  parse: (segment: string) => Effect<A, ParseError>,
  print: (value: A) => string
): Biparser<A>
label: A descriptive name used in error messages.
parse: Converts a raw URL segment string into the parsed value.
print: Converts the parsed value back into a URL segment string.

parseUrlWithFallback

functionsource
/**
 * Parses a URL against a parser, falling back to a not-found route if no
 * parser matches.
 */
<A, B>(
  parser: Parser<A>,
  notFoundRouteConstructor: {
    make: (data: {
      path: string
    }) => B
  }
): (url: Url.Url) => A | B
parser: The parser (typically from `oneOf`) to attempt.
notFoundRouteConstructor: Constructor called with `{ path }` when no route matches.

query

functionsource
/**
 * Adds query parameter parsing to a `Biparser` using an Effect `Schema`.
 * 
 * Produces a `TerminalParser` that cannot be extended with `slash`,
 * since query parameters must appear at the end of a route definition.
 */
<A, I extends ReadonlyRecord<string, unknown>>(schema: Codec<A, I>): (parser: Biparser<B>) => TerminalParser<B & A>
schema: An Effect Schema describing the expected query parameters.

r

functionsource
/**
 * Wraps `Schema.TaggedStruct` to create a route variant you can call directly as a constructor.
 * Use `r` for route types — enabling `Home()` instead of `Home.make()`.
 */
<Tag extends string>(tag: Tag): CallableTaggedStruct<Tag, {}>

<Tag extends string, Fields extends Fields>(
  tag: Tag,
  fields: Fields
): CallableTaggedStruct<Tag, Fields>

slash

functionsource
/**
 * Composes two `Biparser`s sequentially, combining their parsed values.
 * 
 * Cannot be used after `query` since query parameters are terminal.
 */
<A extends Record<string, unknown>, B extends Record<string, unknown>>(parserB: Biparser<A>): (parserA: Biparser<B> & {
  __terminal: undefined
  Cannot use slash after query - query parameters must be terminal: undefined
}) => Biparser<B & A>

string

functionsource
/** Creates a parser that captures a URL segment as a named string field. */
<K extends string>(name: K): Biparser<Record<K, string>>

Types

Biparser

typesource
/**
 * A bidirectional parser that can both parse URL segments into a value
 * and print a value back to URL segments.
 */
type Biparser = {
  parse: (segments: ReadonlyArray<string>, search?: string) => Effect.Effect<ParseResult<A>, ParseError>
  print: (value: A, state: PrintState) => Effect.Effect<PrintState, ParseError>
}

ParseResult

typesource
/** The result of parsing: a tuple of the parsed value and remaining URL segments. */
type ParseResult = [A, ReadonlyArray<string>]

Parser

typesource
/**
 * A parse-only parser with no print/build capabilities.
 * 
 * Returned by `oneOf`, which combines multiple parsers whose print
 * types may differ and therefore cannot be unified into a single `Biparser`.
 */
type Parser = {
  parse: (segments: ReadonlyArray<string>, search?: string) => Effect.Effect<ParseResult<A>, ParseError>
}

Router

typesource
/**
 * A parser with a `build` method that can reconstruct URLs from parsed values.
 * 
 * Created by applying `mapTo` to a `Biparser`, binding it to a tagged
 * type constructor so parsed values carry a discriminant tag and URLs can be
 * built from tag payloads.
 * 
 * Routers are callable — `homeRouter()` or `personRouter({ id: 42 })` —
 * and also expose `.build` as an alias and `.parse` for URL matching.
 */
type Router = BuildFn<A> & {
  build: BuildFn<A>
  parse: (segments: ReadonlyArray<string>, search?: string) => Effect.Effect<ParseResult<A>, ParseError>
}

TerminalParser

typesource
/**
 * A `Biparser` that has been terminated (e.g. by `query`) and cannot
 * be extended with `slash`.
 */
type TerminalParser = Biparser<A> & {
  __terminal: true
}

Constants

mapTo

constsource
/**
 * Converts a `Biparser` into a `Router` by mapping parsed values to a
 * tagged type constructor.
 * 
 * The resulting `Router` can both parse URLs into tagged route values and
 * build URLs from route payloads.
 */
const mapTo: (appRouteConstructor: {
  make: () => T
}) => (parser: Biparser<{}>) => Router<T>

root

constsource
/**
 * A parser that matches the root path with no remaining segments.
 * 
 * Succeeds only when the URL path is exactly `/`.
 */
const root: Biparser<{}>

Stay in the update loop.

New releases, patterns, and the occasional deep dive.


Built with Foldkit.

© 2026 Devin Jameson