oaspec/transport

Pure, runtime-agnostic transport contract for generated OpenAPI clients.

Generated client code depends on this module instead of any concrete HTTP runtime. Adapters (e.g. oaspec/httpc, oaspec/fetch) bridge Send / AsyncSend to a real runtime; tests can plug in arbitrary fake transport values via oaspec/mock.

Types

Cross-target async value used by generated async clients and adapters. JavaScript adapters can back this with promises; other runtimes can bridge from callbacks or scheduling primitives.

pub opaque type Async(value)
pub type AsyncSend =
  fn(Request) -> Async(Result(Response, TransportError))
pub type Body {
  EmptyBody
  TextBody(String)
  BytesBody(BitArray)
}

Constructors

  • EmptyBody
  • TextBody(String)
  • BytesBody(BitArray)
pub opaque type Credentials
pub type Method {
  Get
  Post
  Put
  Delete
  Patch
  Head
  Options
  Trace
  Connect
}

Constructors

  • Get
  • Post
  • Put
  • Delete
  • Patch
  • Head
  • Options
  • Trace
  • Connect
pub type Request {
  Request(
    method: Method,
    base_url: option.Option(String),
    path: String,
    query: List(#(String, String)),
    headers: List(#(String, String)),
    body: Body,
    security: List(SecurityAlternative),
  )
}

Constructors

pub type Response {
  Response(
    status: Int,
    headers: List(#(String, String)),
    body: Body,
  )
}

Constructors

  • Response(
      status: Int,
      headers: List(#(String, String)),
      body: Body,
    )
pub type SecurityAlternative {
  SecurityAlternative(requirements: List(SecurityRequirement))
}

Constructors

pub type SecurityRequirement {
  ApiKeyHeader(scheme_name: String, header_name: String)
  ApiKeyQuery(scheme_name: String, query_name: String)
  ApiKeyCookie(scheme_name: String, cookie_name: String)
  HttpAuthorization(scheme_name: String, prefix: String)
}

Constructors

  • ApiKeyHeader(scheme_name: String, header_name: String)
  • ApiKeyQuery(scheme_name: String, query_name: String)
  • ApiKeyCookie(scheme_name: String, cookie_name: String)
  • HttpAuthorization(scheme_name: String, prefix: String)
pub type Send =
  fn(Request) -> Result(Response, TransportError)
pub type TransportError {
  ConnectionFailed(detail: String)
  Timeout
  InvalidBaseUrl(detail: String)
  TlsFailure(detail: String)
  Unsupported(detail: String)
}

Constructors

  • ConnectionFailed(detail: String)
  • Timeout
  • InvalidBaseUrl(detail: String)
  • TlsFailure(detail: String)
  • Unsupported(detail: String)

Values

pub fn await(
  async async: Async(a),
  next next: fn(a) -> Async(b),
) -> Async(b)
pub fn credentials() -> Credentials
pub fn from_callback(
  register register: fn(fn(value) -> Nil) -> Nil,
) -> Async(value)
pub fn map(
  async async: Async(a),
  with with_: fn(a) -> b,
) -> Async(b)
pub fn map_try(
  async async: Async(Result(a, error)),
  with with_: fn(a) -> Result(b, error),
) -> Async(Result(b, error))
pub fn resolve(value value: a) -> Async(a)
pub fn run(async async: Async(a), done done: fn(a) -> Nil) -> Nil
pub fn try_await(
  async async: Async(Result(a, error)),
  next next: fn(a) -> Async(Result(b, error)),
) -> Async(Result(b, error))
pub fn with_api_key(
  creds creds: Credentials,
  scheme_name scheme_name: String,
  value value: String,
) -> Credentials
pub fn with_base_url(
  send send: fn(Request) -> a,
  base_url base_url: String,
) -> fn(Request) -> a
pub fn with_basic_auth(
  creds creds: Credentials,
  scheme_name scheme_name: String,
  value value: String,
) -> Credentials
pub fn with_bearer_token(
  creds creds: Credentials,
  scheme_name scheme_name: String,
  token token: String,
) -> Credentials
pub fn with_default_header(
  send send: fn(Request) -> a,
  name name: String,
  value value: String,
) -> fn(Request) -> a
pub fn with_default_headers(
  send send: fn(Request) -> a,
  headers headers: List(#(String, String)),
) -> fn(Request) -> a
pub fn with_digest_auth(
  creds creds: Credentials,
  scheme_name scheme_name: String,
  value value: String,
) -> Credentials
pub fn with_security(
  send send: fn(Request) -> a,
  credentials creds: Credentials,
) -> fn(Request) -> a
Search Document