> For the complete documentation index, see [llms.txt](https://docs.navigaglobal.com/writer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.navigaglobal.com/writer/7.0.0/api-reference/writerapi/router.md).

# Router

Router api class with functions for communication with the backend.

All router functions are available through the context.api.router object.

## postBinary(path, file, onProgress, onLoad, onError, params) <a href="#postbinary" id="postbinary"></a>

Post a binary file object to the backend

### Parameters

| Param      | Type       | Description                                             |
| ---------- | ---------- | ------------------------------------------------------- |
| path       | `string`   | **Required -**                                          |
| file       | `object`   | **Required -** File object from file input or file drop |
| onProgress | `function` | **Required -** Callback function for progress event     |
| onLoad     | `function` | **Required -** Callback function for onload event       |
| onError    | `function` | **Required -**                                          |
| params     | `function` | **Required -**                                          |

## post(path, parameters)⇒ `Promise.<Response>` <a href="#post" id="post"></a>

Post data to specified backend endpoint

### Parameters

| Param      | Type     |
| ---------- | -------- |
| path       | `string` |
| parameters | `object` |

## put(path, parameters)⇒ `Promise.<Response>` <a href="#put" id="put"></a>

Put data to specified backend endpoint

### Parameters

| Param      | Type     |
| ---------- | -------- |
| path       | `string` |
| parameters | `object` |

## get(path, parameters)⇒ `Promise.<Response>` <a href="#get" id="get"></a>

Get data from specified backend endpoint

### Parameters

| Param      | Type     | Description                                                                       |
| ---------- | -------- | --------------------------------------------------------------------------------- |
| path       | `string` | **Required -**                                                                    |
| parameters | `object` | **Required -** Could contain headers that will be passed along parameters.headers |

### Example

```javascript
import {api} from 'writer'

api.router.get('/api/binary/url/' + uuid)
    .then((url) => {
        // Handle url
    })
    .catch((error) => {
        console.error(error);
    });
```

## head(path, parameters)⇒ `Promise.<Response>` <a href="#head" id="head"></a>

Fetch specified backend endpoint using a http HEAD request. This is silent and will not produce any error messages.

### Parameters

| Param      | Type     | Description                                                                       |
| ---------- | -------- | --------------------------------------------------------------------------------- |
| path       | `string` | **Required -**                                                                    |
| parameters | `object` | **Required -** Could contain headers that will be passed along parameters.headers |

### Example

```javascript
import {api} from 'writer'

api.router.head('/api/binary/url/' + uuid)
    .then((url) => {
        // Handle url
    })
    .catch((error) => {
        console.error(error);
    });
```

## del(path, parameters)⇒ `Promise.<Response>` <a href="#del" id="del"></a>

Make a DELETE call to a specified backend endpoint

### Parameters

| Param      | Type     | Description                                 |
| ---------- | -------- | ------------------------------------------- |
| path       | `string` | **Required -** Backend endpoint             |
| parameters | `object` | **Required -** Key value request parameters |

## getConceptItem(id, imType)⇒ `*` <a href="#getconceptitem" id="getconceptitem"></a>

Fetch a ConceptItem from the backend

### Parameters

| Param  | Description                          |
| ------ | ------------------------------------ |
| id     | **Required -** The id of the concept |
| imType | **Required -** The x-im/type         |

## getNewsItem(id, imType)⇒ `*` <a href="#getnewsitem" id="getnewsitem"></a>

Fetch a NewsItem from the backend

### Parameters

| Param  | Description                            |
| ------ | -------------------------------------- |
| id     | **Required -** The id of the news item |
| imType | **Required -** The x-im/type           |

## updateConceptItem(uuid, concept)⇒ <a href="#updateconceptitem" id="updateconceptitem"></a>

Updates a Concept Item

**Returns**: A promise with no data

### Parameters

| Param   | Description                                           |
| ------- | ----------------------------------------------------- |
| uuid    | **Required -** The uuid of the Concept Item to update |
| concept | **Required -** The updated XML                        |

## createConceptItem(concept)⇒ `*` | `Promise.<TResult>` <a href="#createconceptitem" id="createconceptitem"></a>

Creates a Concept Item

**Returns**: `*` | `Promise.<TResult>` - containing the resulting UUID

### Parameters

| Param   | Description                          |
| ------- | ------------------------------------ |
| concept | **Required -** The concept to create |

## checkForOKStatus(response)⇒ `*` <a href="#checkforokstatus" id="checkforokstatus"></a>

Method checks for a status code between 200 and 299 Throws error if otherwise.

Use for example when you want to reject a fetch promise

### Parameters

| Param    |
| -------- |
| response |

### Example

```javascript
router.authorizedFetch(...)
    .then(response => checkForOKStatus(response))
    .then(response => toJson(response))
    .then(json => ...)
    .catch(error => ...)
```

## ~~toJson()~~ <a href="#tojson" id="tojson"></a>

***Deprecated***

Use native response.json() instead

## authorizedFetch(url, params)⇒ `Promise.<*>` <a href="#authorizedfetch" id="authorizedfetch"></a>

### Parameters

| Param  | Type     |
| ------ | -------- |
| url    |          |
| params | `object` |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.navigaglobal.com/writer/7.0.0/api-reference/writerapi/router.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
