# URL Extensions

Request, history, and query-string methods RenderJS adds to `URL.prototype`.

## URL

Source: `src/prototype/URL.ts`

| Method / Property | Description |
| --- | --- |
| `url.$queryAll` | Query string parsed into a plain object |
| `url.$image` | Promise resolving a preloaded `Image` for the URL |
| `url.$$200(isImg = false)` | Fetches the URL; if the response is an image, converts it to an object-URL blob (`{ src, img }`) unless it's SVG and `isImg` is falsy |
| `url.$req(body, once = false)` | Fetch wrapper: JSON or `FormData` body (via `body.json`/`body.files`/`body.tag`), custom `header`/`credentials`, request de-duplication through a shared `Map` keyed by URL, automatic JSON/text response parsing, rejects with response text on 4xx/5xx |
| `url.$$query(key)` | `searchParams.get(key)` |
| `url._history(title?)` | `pushState` to this URL, records it in the in-memory history stack, optionally sets `document.title` |
| `url._query(obj)` | Returns a **new** `URL` with `obj`'s keys merged into the existing query string |
| `url.__history(title?)` | `replaceState` to this URL (also updates the history stack) |
| `url.__query(obj)` | Returns a **new** `URL` with the query string replaced entirely by `obj` |
| `url.query_(keys)` | Returns a **new** `URL` with the given key (or array of keys) removed from the query string |
| `url.query__()` | Returns a **new** `URL` with the query string cleared |

## Example

```javascript
const result = await "/api/x".$req({
    method: "POST",
    json: { key: "value" },
    header: { "X-Token": "..." }
});
```
