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

# Scripts and declarations

> How a script is structured, and the difference between request and contract scripts.

Every script is exactly one **declaration** followed by a body in curly braces. The declaration says what kind of script it is, gives it a name and, for contracts, lists its parameters. Nothing may appear before or after the declaration except comments.

```kotlin theme={null}
request MyRequest {
    // The script body goes here
}
```

The body is a sequence of [statements](/language/control-flow) that run from top to bottom until a `return` is reached or the body ends.

## Request scripts

A request is a one-off script. You send it to the server, it runs once, and you get its return value back. Requests don't take parameters.

```kotlin theme={null}
request HelloWorld {
    return "Hello World!"
}
```

Run a request by sending it to [`POST /run`](/reference/http-api#run-a-request).

## Contract scripts

A contract is a script that's saved on the server and invoked later, optionally with parameters.

```kotlin theme={null}
contract path.to.MyContract@1.2.3(name: string, tags: []string) {
    return "Hello ${name}"
}
```

A contract declaration has these parts:

| Part | Example | Required |
| - | - | - |
| Path | `path.to` | No |
| Name | `MyContract` | Yes |
| Version | `@1.2.3` | No. Defaults to `1` |
| Parameters | `(name: string, tags: []string)` | No |

* The **path** is a dot-separated prefix that organizes contracts, like a namespace. Path segments may be any word, including keywords, so `contract if.else.Thing` is allowed.
* The **version** is covered in [Versioning](/contracts/versioning).
* **Parameters** are `name: type` pairs separated by commas, with an optional trailing comma. Parameter names must be unique.
* A contract with no parameters leaves out the parentheses entirely. Writing empty parentheses, `()`, is an error.

```kotlin theme={null}
contract reports.DailySummary {
    return "No parameters needed"
}
```

Inside the body, parameters behave like [`const` variables](/language/variables#const): you can read them but not reassign them.

Save contracts with [`POST /contracts`](/reference/http-api#save-a-contract). See [Contracts](/contracts/overview) for the full workflow.

## Return values

Whatever a script returns becomes the `returnValue` of the HTTP response, encoded as JSON:

```kotlin theme={null}
request Example {
    return { ok: true, items: [1, 2, 3] }
}
```

```json theme={null}
{ "returnValue": { "ok": true, "items": [1, 2, 3] } }
```

If a script ends without a `return`, or uses a bare `return`, the return value is `null`. See [JSON encoding](/reference/json-encoding) for how each type is represented.


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