# Module /http

Shared HTTP method, status code, content-type, and request/response inspection predicates.

```tangu
(use /http)
```

## Functions & symbols

### content-type-of

`(content-type-of msg [default]) -> (Or String None)`

Returns the `Content-Type` header value of an HTTP message.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `msg` | `Map` | no | HTTP request or response Map |
| `default` | `Any` | yes | Optional default value |

```tangu
(server/content-type-of req)
```

### form-of

`(form-of req) -> Map`

Parses an `application/x-www-form-urlencoded` or `multipart/form-data` body into a field Map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let fields (server/form-of req))
```

### get-header

`(header-of msg name [default]) -> (Or String None)`

Performs a case-insensitive lookup of HTTP header `name`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `msg` | `Map` | no | HTTP request or response Map |
| `name` | `String | KeySymbol` | no | Case-insensitive header name |
| `default` | `Any` | yes | Optional default value |

```tangu
(server/header-of req "authorization")
```

### header-of

`(header-of msg name [default]) -> (Or String None)`

Re-export case-insensitive header and URI lookup helpers

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `msg` | `Map` | no | HTTP request or response Map |
| `name` | `String | KeySymbol` | no | Case-insensitive header name |
| `default` | `Any` | yes | Optional default value |

```tangu
(server/header-of req "authorization")
```

### is-delete?

`(is-delete? req)`

Returns `true` when the request method is `"DELETE"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-get?

`(is-get? req)`

Request method and content inspectors
Returns `true` when the request method is `"GET"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-head?

`(is-head? req)`

Returns `true` when the request method is `"HEAD"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-json-request?

`(is-json-request? req)`

Returns `true` if `Accept` prefers JSON or `Content-Type` starts with `application/json`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-options?

`(is-options? req)`

Returns `true` when the request method is `"OPTIONS"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-patch?

`(is-patch? req)`

Returns `true` when the request method is `"PATCH"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-post?

`(is-post? req)`

Returns `true` when the request method is `"POST"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### is-put?

`(is-put? req)`

Returns `true` when the request method is `"PUT"`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Any` | no | — |

### json-of

`(json-of msg) -> Any`

Decodes the JSON body of an HTTP request or response Map into native Tangu data.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let body (server/json-of req))
```

### path-of

`(path-of req) -> String`

Extracts the decoded URI path segment from an incoming request Map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let path (server/path-of req))
```

### query-of

`(query-of req) -> Map`

Parses URL query parameters into a Map (promoting repeated keys into Arrays).

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let q (server/query-of req))
```

### query-string-of

`(query-string-of req) -> String`

Returns the raw URL query string (excluding `?`) from a request Map.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `req` | `Map` | no | Incoming HTTP request Map |

```tangu
(let qs (server/query-string-of req))
```

### request

`(request method url headers body)`

Request / Response constructors
Constructs a typed `#http/Request` map with `method`, `url`, optional `headers`, and optional `body`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `method` | `Any` | no | — |
| `url` | `Any` | no | — |
| `headers` | `Any` | no | — |
| `body` | `Any` | no | — |

### response

`(response status headers body)`

Constructs a typed `#http/Response` map with HTTP `status`, optional `headers`, and optional `body`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `status` | `Any` | no | — |
| `headers` | `Any` | no | — |
| `body` | `Any` | no | — |
