mstksg / servant-cli

Generate a command line client from a servant API
https://hackage.haskell.org/package/servant-cli
BSD 3-Clause "New" or "Revised" License
29 stars 4 forks source link

Nested endpoints #4

Open cblp opened 2 years ago

cblp commented 2 years ago

I have the following API:

type API
    =   "accounts"
        :> QueryParam "asset" Asset
        :> QueryParam "cursor" Text
        :> QueryParam "limit" Natural
        :> Get '[HalJson] (Records Account)
    :<|> "accounts" :> Capture "account_id" Address :> Get '[HalJson] Account
    :<|>
        "accounts" :> Capture "account_id" Address :> "transactions"
        :> QueryParam "cursor" Text :> QueryParam "limit" Natural
        :> Get '[HalJson] (Records Transaction)

And servant-cli give me this:

$ stack run -- horizon --help
Usage: horizon COMPONENT
Available options:
  -h,--help                Show this help text
Path components:
  accounts

$ stack run -- horizon accounts --help
accounts
Usage: horizon accounts [<account_id> | [--asset ASSET] [--cursor TEXT]
                          [--limit NATURAL]]
Available options:
  <account_id>             This account’s public key encoded in a base32 string...
  --asset ASSET            An issued asset represented as...
  --cursor TEXT            From official docs: A number that points to a...
  --limit NATURAL          The maximum number of records returned. The limit can...
  -h,--help                Show this help text

How to call the accounts/:account_id/transactions endpoint?

mstksg commented 10 months ago

Hi, hope you were able to figure this out! Sorry, have been inactive for a while. IIRC (and it's been a while), you would call with horizon accounts myaccount123 transactions.

cblp commented 10 months ago

It's non-intuitive for CLI. And it needs to be documented in --help.