# @mimik/request-helper

> HTTP request helper for mimik microservices

Latest version **2.0.8** (published 2026-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mimik/request-helper
pnpm add @mimik/request-helper
yarn add @mimik/request-helper
bun add @mimik/request-helper
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.8 |
| Published | 2026-07-07 |
| First published | 2018-06-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=24.0.0 |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mimik technology inc |
| Maintainers | mimik-npm-editor, hofachiang, miburger, mimikopensource, sasan.raisdana |
| Keywords | mimik, microservice |

## Links

- npm: https://www.npmjs.com/package/@mimik/request-helper
- Repository: https://bitbucket.org/mimiktech/request-helper
- Homepage: https://bitbucket.org/mimiktech/request-helper#readme
- Issues: https://bitbucket.org/mimiktech/request-helper/issues
- npm.io page: https://npm.io/package/@mimik/request-helper

## Recent versions

- 2.0.8 (latest) — 2026-07-07
- 2.0.7 — 2026-03-22
- 2.0.6 — 2026-03-11
- 2.0.5 — 2026-02-23
- 2.0.4 — 2026-02-19
- 2.0.3 — 2026-02-16
- 2.0.2 — 2025-07-17
- 2.0.1 — 2025-03-25
- 2.0.0 — 2025-02-26
- 1.7.11 — 2024-07-24
- 1.7.10 — 2023-12-04
- 1.7.9 — 2023-08-14
- 1.7.8 — 2022-12-26
- 1.7.7 — 2022-12-02
- 1.7.6 — 2022-05-10
- … 8 more at https://npm.io/package/@mimik/request-helper/versions

## README

<a name="module_request-helper"></a>

## request-helper
**Example**  
```js
// default import
import requestHelper from '@mimik/request-helper';
```
**Example**  
```js
// named imports
import { getCorrelationId, getUserAgent, setUserAgent } from '@mimik/request-helper';
```

* [request-helper](#module_request-helper)
    * [~getCorrelationId([request])](#module_request-helper..getCorrelationId) ⇒ <code>string</code>
    * [~getUserAgent([request])](#module_request-helper..getUserAgent) ⇒ <code>string</code> \| <code>null</code>
    * [~setUserAgent()](#module_request-helper..setUserAgent) ⇒ <code>string</code>

<a name="module_request-helper..getCorrelationId"></a>

### request-helper~getCorrelationId([request]) ⇒ <code>string</code>
Extract or generate a correlationId in the format `uuid@step/date`.
Reads the `x-correlation-id` or `X-Correlation-Id` header from the request and increments the step.
If no correlationId exists, generates a new one with step 0 and the current timestamp.
If the step is not a number, it is reset to 0.

**Kind**: inner method of [<code>request-helper</code>](#module_request-helper)  
**Returns**: <code>string</code> - The correlationId in `uuid@step/date` format.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| [request] | <code>object</code> \| <code>string</code> | The request object with headers, or a correlationId string. Other types generate a new correlationId. |

<a name="module_request-helper..getUserAgent"></a>

### request-helper~getUserAgent([request]) ⇒ <code>string</code> \| <code>null</code>
Extract the `user-agent` header from the request.

**Kind**: inner method of [<code>request-helper</code>](#module_request-helper)  
**Returns**: <code>string</code> \| <code>null</code> - The user-agent string, or null if not available.  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| [request] | <code>object</code> | The request object containing headers. If omitted or without headers, null is returned. |

<a name="module_request-helper..setUserAgent"></a>

### request-helper~setUserAgent() ⇒ <code>string</code>
Build a user-agent string identifying this server instance.
Returns a string in the format `mimik-type/version/id (platform; arch; runtime)`.

The following environment variables are optionally used:

| Env variable name | Description | Default | Comments |
| ----------------- | ----------- | ------- | -------- |
| SERVER_TYPE | type of the server instance that makes the call | genericType | for defining the agent |
| SERVER_VERSION | version of the server instance that makes the call | 1.0 | for defining the agent |
| SERVER_ID | id of the server instance that makes the call | generic | for defining the agent |

**Kind**: inner method of [<code>request-helper</code>](#module_request-helper)  
**Returns**: <code>string</code> - The user-agent string to be added to outgoing requests.  
**Category**: sync

---
_Source: https://npm.io/package/@mimik/request-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
