# nameless-js

> Nameless is a utility that allows actions to be dispatched from the client that will trigger server side functionality. Useful for updating data on the server using things like Redux.

Latest version **0.5.3** (published 2017-02-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install nameless-js
pnpm add nameless-js
yarn add nameless-js
bun add nameless-js
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.3 |
| Published | 2017-02-27 |
| First published | 2016-12-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | realseanp |
| Maintainers | rsp2000 |
| Keywords | redux, react, api, redux-api |

## Links

- npm: https://www.npmjs.com/package/nameless-js
- Repository: https://github.com/realseanp/nameless-js/
- npm.io page: https://npm.io/package/nameless-js

## Dependencies (1)

- [body-parser](https://npm.io/package/body-parser.md) ^1.15.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.5.3 (latest) — 2017-02-27
- 0.5.2 — 2017-02-27
- 0.5.1 — 2017-02-27
- 0.5.0 — 2017-02-25
- 0.4.0 — 2017-02-25
- 0.3.0 — 2017-02-25
- 0.2.0 — 2017-02-04
- 0.1.0 — 2016-12-25
- 0.0.9 — 2016-12-21
- 0.0.8 — 2016-12-21
- 0.0.7 — 2016-12-21
- 0.0.6 — 2016-12-21
- 0.0.5 — 2016-12-20
- 0.0.4 — 2016-12-20
- 0.0.3 — 2016-12-20
- … 2 more at https://npm.io/package/nameless-js/versions

## README

[![Build Status](https://travis-ci.org/realseanp/nameless-js.svg?branch=master)](https://travis-ci.org/realseanp/nameless-js)

# Nameless JS - Isomorphic Client/Server Communication

Nameless is a utility that tries to make server/client communication easier. Built for isomorphic apps, Nameless dispatches actions from the client and the server the same way. These actions are tied to methods set up server-side. So when actions are dispatched we can interact with databases (or do other async stuff) and send data back to the client.

Nameless was initially built to be used with a Redux app, but you can use it any way you see fit!

```bash
npm i --save nameless-js
```
```bash
import namelessClient from 'nameless-js/client';
import namelessServer, { createService } from 'nameless-js/server';
```

A client side call to the server might look like. If this function is called server side you will get the same results.

```js
nameless.exec('jobs', actions.FILTER_JOBS, { /* filters */ }).then(data => /* do something with data. update store ? */ )));
```

## Getting Started

The first thing you will want to do is [get Nameless working with your server](https://github.com/realseanp/nameless-js/blob/master/read/server.md)


## Api

### Server

```js
import nameless, { createService } from 'nameless-js/server';
```

**`nameless(config = Object, app = Express Object)`**

**Arguments**

`config` - Object

- **Object Properties**

  - `apiPrefix` - String - The path you want Nameless to use for your API.

  - `services` - Array - Array of service objects

`app` - Express object - [Example](http://expressjs.com/en/4x/api.html#express)

**Returns**

`Object` - An object is returned with two properties `commander` and `apiPrefix`.

- `commander` - Object
  - `exec(serviceName = String, actionName = String)`- Promise
- `apiPrefix` - String - String you specified in `config` object.

**`createService(name = String, actions = Object)`**

`name` - String - Name of your service

`actions` - Object - An object containing action methods.

- `[ACTION_METHOD_NAME](payload, resolve, reject, req, res, next)` - Function that will be executed when action correlating to this functions name is executed.

#### Error Handling On The Server

To return an error from your server-side functions simply reject the promise and pass in an object with the properties `code` and `message`.

```js
  [ACTION_METHOD_NAME](payload, resolve, reject, req, res, next) {
    // do something
    // ...
    // ...
    if(error) {
      reject({
        code: 400,
        message: 'Bad request',
      });
    }
  }
```

### Client

```js
import nameless from 'nameless-js';
```

**`nameless(apiPrefix = String)`**

**Arguments**

`apiPrefix` - String - Path specified in server configuration object.

**Returns**

`Object` - An object containing the `exec` method

- `exec(serviceName = String, actionName = String, payload)`

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