# getHealth

Check whether a SWQoS edge is ready to accept sends. Readiness does not guarantee that a transaction will land.

Source: https://docs.zerocopy.sh/api/health

`POST https://sol.zerocopy.sh/`

Authentication: API key, one of: `x-api-key` header, `api-key` query, `Authorization: Bearer` header.

## Request body (`application/json`)

One JSON object, at most 65,536 bytes, received within 2 seconds. Batches are not supported. The method takes no params. The [ZeroCopy Agent](/agent/http) reports its own state.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `jsonrpc` | `"2.0"` | yes |  |
| `id` | string or number or null | no | Optional request id, echoed exactly in the response. Null when absent or refused before the id could be read. |
| `method` | `"getHealth"` | yes |  |
| `params` | any | no | Ignored when present. |

```json title="Request"
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getHealth"
}
```

## Responses

### 200

Returns `ok` when the edge is ready to accept sends, not when landing is guaranteed.

Refusals with HTTP 200, by `error.data.reason`:

- [`invalid_request`](/errors#invalid_request): invalid JSON-RPC body.

```json title="Success"
{
  "jsonrpc": "2.0",
  "result": "ok",
  "id": 1
}
```

```json title="Invalid JSON"
{
  "jsonrpc": "2.0",
  "error": {
    "code": -32700,
    "message": "the body is not valid JSON",
    "data": {
      "reason": "invalid_request",
      "problem": "parse_error",
      "message": "the body is not valid JSON",
      "retryable": false,
      "docs": "https://docs.zerocopy.sh/errors#invalid_request"
    }
  },
  "id": null
}
```

### 401

[`unauthorized`](/errors#unauthorized): missing, unknown or revoked API key.

```json title="unauthorized"
{
  "jsonrpc": "2.0",
  "error": {
    "code": -32000,
    "message": "API key missing or not recognized; pass it as the api-key query parameter, an x-api-key header or Authorization: Bearer",
    "data": {
      "reason": "unauthorized",
      "message": "API key missing or not recognized; pass it as the api-key query parameter, an x-api-key header or Authorization: Bearer",
      "retryable": false,
      "docs": "https://docs.zerocopy.sh/errors#unauthorized"
    }
  },
  "id": null
}
```

### 503

The edge is not ready. Returns JSON-RPC code `-32005` and message `Node is unhealthy`, without a `data` member.

```json title="Unhealthy"
{
  "jsonrpc": "2.0",
  "error": {
    "code": -32005,
    "message": "Node is unhealthy"
  },
  "id": 1
}
```

## Code samples

```ts title="TypeScript"
// Uses the client helper from the API overview (/api#client-helper).
import { call, SwqosError } from './swqos.ts'

try {
  console.log('health', await call<string>('getHealth'))
} catch (error) {
  if (error instanceof SwqosError && error.code === -32005) console.log('edge not ready')
  else throw error
}
console.log('slot', await call<number>('getSlot'))
```

```rust title="Rust"
// Uses the client helper from the API overview (/api#client-helper).
use swqos_examples::swqos::{Result, SwqosError, call};

#[tokio::main]
async fn main() -> Result<()> {
    match call::<String>("getHealth", None).await {
        Ok(health) => println!("health {health}"),
        Err(error) => {
            if error
                .downcast_ref::<SwqosError>()
                .is_some_and(|error| error.code == -32005)
            {
                println!("edge not ready");
            } else {
                return Err(error);
            }
        }
    }
    let slot: u64 = call("getSlot", None).await?;
    println!("slot {slot}");
    Ok(())
}
```

```go title="Go"
// Uses the client helper from the API overview (/api#client-helper).
package swqos

import (
	"context"
	"errors"
	"fmt"
)

func PrintHealth(ctx context.Context) error {
	health, err := Call[string](ctx, "getHealth")
	if err != nil {
		var refusal *SwqosError
		if !errors.As(err, &refusal) || refusal.Code != -32005 {
			return err
		}
		fmt.Println("edge not ready")
	} else {
		fmt.Println("health", health)
	}
	slot, err := Call[uint64](ctx, "getSlot")
	if err != nil {
		return err
	}
	fmt.Println("slot", slot)
	return nil
}
```
