<commit_before>---
title: Getting Started
---

Gatsby Functions help you build [Express-like](https://expressjs.com/) backends without running servers.

## Hello World

JavaScript and Typescript files in `src/api/*` are mapped to function routes like files in `src/pages/*` become pages.

For example, the following Function is run when you visit the URL `/api/hello-world`

```js:title=src/api/hello-world.js
export default function handler(req, res) {
  res.status(200).json({ hello: `world` })
}
```

A Function file must export a single function that takes two parameters:

- req: An instance of [http.IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage) with some [automatically parsed data](/docs/how-to/functions/getting-started/#common-data-formats-are-automatically-parsed)
- res: An instance of [http.ServerResponse](https://nodejs.org/api/http.html#http_class_http_serverresponse) with some [helper functions](/docs/how-to/functions/middleware-and-helpers/#res-helpers)

Dynamic routing is supported for creating REST-ful APIs and other uses cases

- `/api/users` => `src/api/users/index.js`
- `/api/users/23` => `src/api/users/[id].js`

[Learn more about dynamic routes](/docs/how-to/functions/routing#dynamic-routing)

## Typescript<commit_msg>feat(docs): Add notice that functions need flag enabled + simplify description of req/res (#31354)<commit_after>---
title: Getting Started
---

Gatsby Functions help you build [Express-like](https://expressjs.com/) backends without running servers.

Functions are currently in beta and can be enabled by adding the `FUNCTIONS` flag to your `gatsby-config.js` to sites running Gatsby 3.4 and above. [Learn more and join the discussion](https://github.com/gatsbyjs/gatsby/discussions/30735).

## Hello World

JavaScript and Typescript files in `src/api/*` are mapped to function routes like files in `src/pages/*` become pages.

For example, the following Function is run when you visit the URL `/api/hello-world`

```js:title=src/api/hello-world.js
export default function handler(req, res) {
  res.status(200).json({ hello: `world` })
}
```

A Function file must export a single function that takes two parameters:

- req: An instance of the [Node.js HTTP request object](https://nodejs.org/api/http.html#http_class_http_incomingmessage) with some [automatically parsed data](/docs/how-to/functions/getting-started/#common-data-formats-are-automatically-parsed)
- res: An instance of the [Node.js HTTP response object](https://nodejs.org/api/http.html#http_class_http_serverresponse) with some [extra helper functions](/docs/how-to/functions/middleware-and-helpers/#res-helpers)

Dynamic routing is supported for creating REST-ful APIs and other uses cases

- `/api/users` => `src/api/users/index.js`
- `/api/users/23` => `src/api/users/[id].js`

[Learn more about dynamic routes](/docs/how-to/functions/routing#dynamic-routing)

## Typescript
{'fraction_non_alphanumeric': 0.12798634812286688, 'fraction_numerical': 0.007508532423208191, 'mean_word_length': 4.827037773359841, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5517305', 'n_tokens_mistral': 917, 'n_tokens_neox': 881, 'n_words': 266}