joker

A gleam library for fetching jokes from the JokeAPI service.

This library provides a simple interface to retrieve jokes from the JokeAPI (v2.jokeapi.dev), with built-in error handling and type-safe JSON decoding. It supports fetching random jokes with detailed metadata including categories, content flags, and safety ratings.

Features

Types

The library provides structured types for joke responses including:

Package Version Hex Docs

gleam add joker@1
import jokeapi/api

pub fn main() -> Nil {
  let joke = api.get_any()
  case joke {
    Ok(j) -> {
      api.display_joke(j)
    }
    Error(err) ->
      io.println(
        "Error fetching joke: "
        <> case err {
          api.DecodeError(reason) -> "Decode Error: " <> reason
          api.GenericError(reason) -> "Generic Error: " <> reason
          api.RequestError(reason) -> "Request Error: " <> reason
        },
      )
  }
}

Further documentation can be found at https://hexdocs.pm/joker.

Development

gleam run   # Run the project
gleam test  # Run the tests
Search Document