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

# hitspec init

> Initialize a new hitspec project with a config file and example test.

# hitspec init

Initialize a new hitspec project in the current directory.

```bash theme={null}
hitspec init [flags]
```

## What It Creates

| File | Description |
| - | - |
| `hitspec.yaml` | Configuration file with default environments (dev, staging, prod) |
| `example.http` | Example requests (health check, create, get) with assertions, a capture, and `>>>mock` blocks so `hitspec mock` can serve them |

## Flags

| Flag | Short | Description | Default |
| - | - | - | - |
| `--force` | `-f` | Overwrite existing files | `false` |

## Examples

```bash theme={null}
# Initialize a new project
hitspec init

# Overwrite existing files
hitspec init --force
```

## Generated Config

The generated `hitspec.yaml` includes:

```yaml theme={null}
defaultEnvironment: dev
timeout: 30000
retries: 0
followRedirects: true
maxRedirects: 10
validateSSL: true
headers:
  User-Agent: hitspec
environments:
  dev:
    baseUrl: http://localhost:3000
  staging:
    baseUrl: https://staging.api.example.com
  prod:
    baseUrl: https://api.example.com
```

## Generated Example

The generated `example.http` demonstrates:

* Variable definitions with `@baseUrl`
* Request metadata (`@name`, `@description`, `@tags`)
* Assertion blocks with `>>>` / `<<<`
* Capture blocks with `>>>capture` / `<<<`
* Dependencies with `@depends`

## Run the Example

The example is self-contained: `hitspec mock` serves it from its own `>>>mock` blocks, so it passes without an API of your own. Use two terminals:

```bash theme={null}
# Terminal 1: serve example.http on the dev baseUrl (http://localhost:3000)
hitspec mock example.http --port 3000

# Terminal 2: run it
hitspec run example.http
```

`hitspec run` ignores `>>>mock` blocks. To test a real API, set `baseUrl` in `hitspec.yaml` and replace the requests in `example.http`.

The line `@baseUrl = {{baseUrl}}` at the top of `example.http` makes the file default to the `baseUrl` of the active environment. See [Variables](https://hitspec.dev/concepts/variables.md).


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