google_youtube_api_v3/request

Sans-IO HTTP runtime for the generated YouTube API bindings.

This module never performs I/O. It describes requests as data (Request), converts them to gleam/http records, applies credentials to them, and parses responses back into the generated types. Executing a request against a real transport is the caller’s job — see the module documentation for a gleam_httpc one-liner.

Types

The error object inside a non-2xx YouTube API response.

pub type ApiError {
  ApiError(status: Int, code: Int, message: String)
}

Constructors

  • ApiError(status: Int, code: Int, message: String)

How a request authenticates.

pub type Credentials {
  ApiKey(String)
  OAuthToken(String)
}

Constructors

  • ApiKey(String)

    A public API key, sent as the key query parameter.

  • OAuthToken(String)

    An OAuth 2.0 access token, sent as a bearer Authorization header.

A fully-described API call. Build one with the generated *_request functions (e.g. youtube/api/videos.list_request), attach credentials with authorize, then execute it with your own HTTP client.

The verb is gleam/http’s Method so requests plug straight into ecosystem clients; only Get/Post/Put/Delete are ever generated.

pub type Request {
  Request(
    method: http.Method,
    path: String,
    query: List(#(String, String)),
    headers: List(#(String, String)),
    scopes: List(String),
    body: option.Option(String),
  )
}

Constructors

  • Request(
      method: http.Method,
      path: String,
      query: List(#(String, String)),
      headers: List(#(String, String)),
      scopes: List(String),
      body: option.Option(String),
    )

An API-level failure: either the transport answered with a non-2xx status carrying Google’s standard error body, or the body did not decode with the supplied decoder.

pub type RequestError {
  HttpError(ApiError)
  DecodeError(json.DecodeError)
}

Constructors

Values

pub fn authorize(
  request: Request,
  credentials: Credentials,
) -> Request

Attach credentials to a request. An API key is appended to the query parameters; an OAuth token becomes an Authorization header.

pub fn error_message(
  body: String,
) -> Result(String, json.DecodeError)

Decode just the error object of a failure body, without a status code.

pub fn parse_response(
  status: Int,
  body: String,
  decoder: decode.Decoder(a),
) -> Result(a, RequestError)

Parse a completed HTTP exchange. Successful (2xx) bodies decode with the generated decoder(); anything else decodes the standard error object. Transport-level failures never reach this function — they are your HTTP client’s errors, not the API’s.

pub fn query_param(
  request: Request,
  name: String,
) -> option.Option(String)

Look up the first value of a query parameter.

pub fn required_scopes(request: Request) -> List(String)

Extract the OAuth scopes a request needs, for display on consent screens or for requesting tokens up front.

pub fn to_http_request(
  request: Request,
) -> request.Request(String)

Convert a Sans-IO request into a gleam/http request record, ready to hand to any ecosystem client (e.g. gleam_httpc’s send). Pure. Query encoding is left to gleam/http, which owns it.

pub fn to_url(request: Request) -> String

Render a request’s full URL for display and logging: root + path + encoded query string. Pure.

✨ Search Document