我正在进行的项目涉及调用 CloudFlare API。我已经使用 Servant(客户端)定义了 API,并且可以从中创建一个客户端。但是,CloudFlare API 需要身份验证标头,因此我的所有 API 类型最终都会重复。有没有办法在类型级别摆脱那些?我对客户端派生函数需要这些参数感到满意。
示例代码:
type ListZones = "zones"
:> Header "X-Auth-Email" Text
:> Header "X-Auth-Key" Text
:> Get '[JSON] (Result [Zone])
type ListRecords = "zones"
:> Header "X-Auth-Email" Text
:> Header "X-Auth-Key" Text
:> Capture "zone_uuid" Text
:> "dns_records"
:> Get '[JSON] (Result [Record])
type CreateRecord = "zones"
:> Header "X-Auth-Email" Text
:> Header "X-Auth-Key" Text
:> Capture "zone_uuid" Text
:> "dns_records"
:> ReqBody '[JSON] Record
:> Post '[JSON] (Result Record)
type UpdateRecord = "zones"
:> Header "X-Auth-Email" Text
:> Header "X-Auth-Key" Text
:> Capture "zone_uuid" Text
:> "dns_records"
:> Capture "record_uuid" Text
:> ReqBody '[JSON] Record
:> Patch '[JSON] (Result Record)