# @truefusion/somnia

> Beautifully RESTful.

Latest version **0.0.6** (published 2024-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @truefusion/somnia
pnpm add @truefusion/somnia
yarn add @truefusion/somnia
bun add @truefusion/somnia
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2024-10-12 |
| First published | 2023-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 2 |
| Unpacked size | 38.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | aimfornan |
| Keywords | fetch, api, json, rest, restful |

## Links

- npm: https://www.npmjs.com/package/@truefusion/somnia
- Repository: https://github.com/AimForNaN/somnia
- Issues: https://github.com/AimForNaN/somnia/issues
- npm.io page: https://npm.io/package/@truefusion/somnia

## Dependencies (2)

- [ufo](https://npm.io/package/ufo.md) ^1.1.2
- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.21

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.6 (latest) — 2024-10-12
- 0.0.5 — 2023-11-16
- 0.0.4 — 2023-06-15
- 0.0.3 — 2023-06-15
- 0.0.2 — 2023-06-07
- 0.0.1 — 2023-06-07

## README

# somnia

Beautifully RESTful.

## Installation

```bash
npm install @truefusion/somnia --save
```

## API

Basic syntax: `somnia(URL, OPTIONS).METHOD(DATA, OPTIONS): Promise`

**METHOD:** HTTP verb.<br>
**OPTIONS:** [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options) options.

## Examples

```javascript
import somnia from 'somnia';

var blog = somnia('/blog');

/* /blog/posts */
var posts = blog('posts');
posts.post({
    title: 'somnia',
});

/* /blog/posts?category=javascript */
posts.get({
    category: 'javascript',
});

/* /blog/posts/1 */
var firstPost = posts(1);
firstPost.get();
firstPost.put({ title: 'somnia is simple' });
firstPost.patch({ title: 'somnia is really simple' });
firstPost.delete();

var firstPostComments = firstPost('1/comments');

/* /blog/posts/1/comments */
firstPostComments.get();

/* /blog/posts/1/comments/1 */
firstPostComments(1).get();
```

Easily converts to string:

```javascript
String(somnia('/blog/posts')) // "/blog/posts"
```

To catch errors:

```javascript
somnia('/posts')
  .get()
  .catch(function({ statusText }) {
    console.log(statusText);
});
```

Options are inherited:

```javascript
var posts = somnia('/blog/posts', fetchOptions);
var comments = posts('1/comments'); // Will inherit fetchOptions
```

Provide your own drop-in replacement for `fetch`:

```javascript
import fetch from 'node-fetch';

var blog = somnia('/blog', { fetch });
```

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