For AI agents: the complete documentation index is available at /byethrow/llms.txt, the full documentation bundle is available at /byethrow/llms-full.txt, and this page is available as Markdown at /byethrow/examples/api-request-cli.md.
  • English
  • API Request CLI

    This example is a command-line application that fetches data from PokéAPI. list prints a page of Pokémon names, and describe <name> prints the details of a single Pokémon. It shows how to build a robust HTTP client where every failure is represented in the type.

    What This Example Shows

    • Typed HTTP errors: The fetch wrapper distinguishes network errors, timeouts, non-OK HTTP statuses, and invalid JSON, each as its own error class in a FetchError union.
    • Timeouts: A timeout that resolves to a Failure races against the request with Promise.race.
    • Rejecting responses: Result.andThen turns a response with a non-OK status into a Failure, as described in Chaining Results.
    • Reusable wrappers: retry and cache are higher-order functions that wrap any function returning a ResultAsync, and are applied with Result.pipe.
    • Response validation: API responses are validated with a Valibot schema and Result.parse.
    • Input validation: The --page argument is converted to an integer with a function that returns a Result.