# Formalising external APIs

DevFeed: [Formalising external APIs](<https://devfeed.tech/articles/formalising-external-apis-51504.md>)

Original publisher: [Read original article](<https://gleam.run/news/formalising-external-apis>)

Author: Louis Pilfold

Published: 2025-10-19T00:00:00Z

Content type: release

Language: en

Sources: [Gleam](<https://devfeed.tech/sources/gleam.md>)

Topics: [Tool](<https://devfeed.tech/topics/tool.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>), [adapter pattern](<https://devfeed.tech/topics/adapter-pattern.md>), [Erlang](<https://devfeed.tech/topics/erlang.md>), [code beautification](<https://devfeed.tech/topics/code-beautification.md>), [import](<https://devfeed.tech/topics/import.md>), [modules](<https://devfeed.tech/topics/modules.md>), [Sequences](<https://devfeed.tech/topics/sequences.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [identifier](<https://devfeed.tech/topics/identifier.md>), [Exception handling](<https://devfeed.tech/topics/exception-handling.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [apis](<https://devfeed.tech/tags/apis.md>), [beam](<https://devfeed.tech/tags/beam.md>), [data](<https://devfeed.tech/tags/data.md>), [data-types](<https://devfeed.tech/tags/data-types.md>), [ecosystem](<https://devfeed.tech/tags/ecosystem.md>), [ecosystems](<https://devfeed.tech/tags/ecosystems.md>), [elixir](<https://devfeed.tech/tags/elixir.md>), [erlang](<https://devfeed.tech/tags/erlang.md>), [external](<https://devfeed.tech/tags/external.md>), [interface](<https://devfeed.tech/tags/interface.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [overhead](<https://devfeed.tech/tags/overhead.md>), [performance](<https://devfeed.tech/tags/performance.md>), [wrapper](<https://devfeed.tech/tags/wrapper.md>)

## AI overview

Gleam v1.13.0 adds a documented guide for externals and a dedicated JavaScript API for constructing and inspecting Gleam data. Existing JavaScript externals will need to migrate, with tooling and team help planned. The compiler also prunes redundant bit-array checks and warns about impossible bit patterns, unused recursive arguments, and inefficient list-length emptiness checks. Build output now reports dependency changes to support auditing locked versions. Many language-server improvements add or refine code actions, including extracting functions, expanding and collapsing pattern matches, and generating functions across modules; extraction uses a placeholder name because of an LSP limitation. Other changes improve type names in generated documentation and editor actions, syntax diagnostics, and formatter behavior.

## Source excerpt

Gleam is a type-safe and scalable language for the Erlang virtual machine and JavaScript runtimes. Today Gleam v1.13.0 has been published. Let's go over all the highlights now. External API for Gleam data One of Gleam's strengths is that it is part of the BEAM and JavaScript ecosystems, enabling Gleam programs to take advantage of code written in Erlang, Elixir, JavaScript, and more. This is a large part of how Gleam was able to become a practical production-ready language so quickly, by not restricting Gleam programmers to just the comparatively young Gleam package ecosystem. A function written in one of these other languages can be imported into a Gleam module as an "external function", and then called without any additional performance overhead. @external(erlang, "moon_base", "launch_spaceship") pub fn lift_off(countdown: Int) -> Result(Spaceship, LaunchError) Here the Erlang function launch_spaceship from the module moon_base is being imported. One restriction to external functions is that they will need to return data types that Gleam can understand. Gleam's "external type" feature lets the programmer refer to types defined in other languages, but if the programmer wants to be able to directly construct and pattern match data from external functions it will need to be in a format compatible with Gleam data types. Often a programmer will write a small wrapper function in the external language to convert the data, and also to make the interface adhere to Gleam patterns and conventions. -module(moon_base). -export([launch_spaceship/1]). launch_spaceship(Countdown) -> try Spaceship = launch_control:launch_spaceship(Countdown), {ok, Spaceship} catch error:no_fuel -> {error, no_fuel}; error:bad_weather -> {error, bad_weather} end. This launch_spaceship Erlang function wraps the function from the launch_control module, converting the exception-based API into a Result type, the Erlang representation of Gleam's Ok and Error variants. One thing that a Gleam programmer ma