# Fig: Simple and Extensible Configuration

**URL:** <https://racket.discourse.group/t/fig-simple-and-extensible-configuration/2551>\
**Category:** General\
**Created:** [November 29, 2023, 12:40am UTC](https://racket.discourse.group/t/fig-simple-and-extensible-configuration/2551 "2023-11-29T00:40:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![micah\_cantor](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/micah_cantor/32/1545_2.png) [@micah\_cantor](https://racket.discourse.group/u/micah_cantor)\
**Post date:** [November 29, 2023, 12:40am UTC](https://racket.discourse.group/t/fig-simple-and-extensible-configuration/2551/1 "2023-11-29T00:40:27Z")

</div>

Hi everyone, I released a tiny `#lang` for configuration:

[Fig](https://docs.racket-lang.org/fig/) is a domain-specific language for composing con_fig_uration files. Fig is a super-set of JSON with some additional features to reduce repetition and increase correctness. These features include:

- **Variables** : Don’t repeat yourself! Name and reuse parts of the configuration.
- **Input** : Include an environment of input variables to generalize the configuration to different contexts.
- **Merge** : Create small, reusable objects; then combine them into more complex parts.

Here’s a configuration for a web service that demonstrates these features, saved in a file named config.fig:

```scheme
#lang fig
 
let user-info = {
  "username": @username,
  "email": @email
}
let server-info = {
  "base": if @local then "http://localhost:3000" else "https://website.com",
  "endpoints": ["/cats", "/dogs"]
}
user-info & server-info

```

Here we have two objects, `user-info` and `server-info` that expect a few input variables (each prefixed with the `@` operator) to be provided: a username, an email, and a flag for if the service is running locally. These two objects are merged together using the & operator.

Then, in the following Racket program, we instantiate this Fig configuration by providing the required variables:

```scheme
#lang racket/base
 
(require "config.fig")
 
(fig->json (hash "username" "cat"
                 "email" "cat@email.com"
                 "local" #t))

```

By requiring the Fig file, we obtain the fig-\>json procedure for that configuration. By applying this procedure to a table of inputs, we obtain the following JSON output:

```scheme
{
  "username": "cat",
  "email": "cat@cat.com"
  "base": "http://localhost:3000",
  "endpoints": ["/cats", "/dogs"]
}

```

For more information, see the [documentation](https://docs.racket-lang.org/fig/) and the [source code](https://github.com/micahcantor/fig).

---

<div class="post-metadata">

**Author:** ![SamPhillips](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samphillips/32/15_2.png) [@SamPhillips](https://racket.discourse.group/u/SamPhillips)\
**Post date:** [November 29, 2023, 10:42pm UTC](https://racket.discourse.group/t/fig-simple-and-extensible-configuration/2551/2 "2023-11-29T22:42:56Z")

</div>

This looks real cool. Thanks for sharing!
