> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ollie.shop/llms.txt
> Use this file to discover all available pages before exploring further.

# What are Functions

> Server-side code that intercepts the checkout's calls to your commerce platform: rewrite a request, replace a response, enrich the session, or stop a call, without touching the checkout UI

A **function** is a small TypeScript program that runs between the Ollie checkout and your commerce platform. Every call the checkout server makes to the platform (loading the cart, adding an item, saving the address, placing the order) goes through Ollie's **hub**, and the hub runs the functions whose [trigger](/ollie-shop/functions/triggers.md) matches that call.

```
checkout server ──▶ hub ──▶ request functions ──▶ platform (VTEX) ──▶ response functions ──▶ hub ──▶ checkout server
                                 │                                         │
                        rewrite the request                      rewrite the response
                        or answer it yourself                    or leave it as it is
```

With a function you can:

* **Change what is sent** to the platform: a request function receives the outgoing request and can return a modified one (different body, headers or URL).
* **Change what comes back**: a response function receives the platform's response and can return a modified one, for example to add a computed field the checkout then exposes under `session.extensions`.
* **Answer a call yourself**: a request function that returns a `Response` skips the platform entirely. Used for validations and for rejecting an action with a message the shopper sees.
* **Remember things across calls** with a per-shopper [session storage](/ollie-shop/functions/session-storage-and-cookies.md), and set cookies on the shopper's browser.
* **Call other systems** (fraud checks, ERP validation, pricing services) using secrets from the store's [Environment Variables](/ollie-shop/configuration/env-vars.md).

Functions complement [components](/ollie-shop/concepts/component.md): components change what the shopper sees, functions change the data the checkout works with. A rule that must hold regardless of UI, such as "this item cannot ship to that region", belongs in a function.

![Function General Configuration](https://mintcdn.com/ollie/ZKpSeyUd64Smy50J/images/admin-function-general.png?fit=max\&auto=format\&n=ZKpSeyUd64Smy50J\&q=85\&s=3ccba11d5e2a2f10a3e55d5d8893c9ba)

A function in the Admin: trigger URL, HTTP method, trigger type, conditions, priority and error behaviour

## The two kinds

| Trigger type | Runs | Receives | Can return |
| - | - | - | - |
| **Request** | before the platform is called | `req` (the outgoing request), `res` is `null` | a new `Request` to send instead, a `Response` to answer without calling the platform, or nothing |
| **Response** | after the platform answered | `req` (what was sent) and `res` (what came back) | a new `Response` to pass on, or nothing |

All matching request functions run first, in priority order, then the platform is called once, then all matching response functions run. Details and the full contract are in [Writing a function](/ollie-shop/functions/writing-a-function.md).

## What a function sees

Only calls the **checkout server** makes to the platform pass through the hub. That covers the cart and checkout API (`orderForm`, items, attachments, coupons, simulation, pickup points, the order page) and any URL a custom component requests through the `REQUEST` action of [`useCheckoutAction`](/ollie-shop/api/useCheckoutAction). It does **not** cover card payment submissions (they go straight from the browser to the payment vault), installment lookups, or anything the shopper's browser fetches directly. [Triggers](/ollie-shop/functions/triggers.md#which-calls-can-be-intercepted) lists the endpoints.

## Where functions live

Each function is a record in a store [version](/ollie-shop/concepts/version.md) with a trigger, a type, a priority and an error policy, plus the code you deploy to it. You create the record in the Admin (**Functions → Create Function**) or with the CLI, write the code in your project's `functions/<name>/` folder, test it with [`ollieshop function dev`](/ollie-shop/cli/function-dev), and ship it with [`ollieshop deploy`](/ollie-shop/cli/deploy). See [Deploying a function](/ollie-shop/functions/deploying.md).

## Limits worth knowing up front

* A function has **5 seconds** to run, including any external call it makes. Keep remote calls short and set your own timeouts.
* Functions run on their own servers, not in the shopper's browser: no `window`, no DOM.
* Session storage holds about 2 KB per shopper; it is for ids and small flags, not for copies of the cart.
* If a function with error behaviour **Throw** fails, the checkout call fails and the shopper sees a generic error. Prefer **Skip** for anything that is not a hard rule, and handle your own errors.

## Next

> **[Writing a function](/ollie-shop/functions/writing-a-function.md)**
>
> The handler contract, return values, chaining, errors and limits

> **[Triggers](/ollie-shop/functions/triggers.md)**
>
> Which calls to intercept and the condition language

> **[Session storage and cookies](/ollie-shop/functions/session-storage-and-cookies.md)**
>
> Remembering things per shopper

> **[Deploying](/ollie-shop/functions/deploying.md)**
>
> From the record in the Admin to a live function


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.