# servify

> Microservices the simplest way conceivable.

Latest version **0.1.12** (published 2017-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install servify
pnpm add servify
yarn add servify
bun add servify
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.12 |
| Published | 2017-08-03 |
| First published | 2017-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 29 |
| Author | MaiaVictor |
| Maintainers | maiavictor |

## Links

- npm: https://www.npmjs.com/package/servify
- Repository: https://github.com/maiavictor/servify
- Homepage: https://github.com/maiavictor/servify#readme
- Issues: https://github.com/maiavictor/servify/issues
- npm.io page: https://npm.io/package/servify

## Dependencies (5)

- [xhr](https://npm.io/package/xhr.md) ^2.3.3
- [cors](https://npm.io/package/cors.md) ^2.8.1
- [express](https://npm.io/package/express.md) ^4.14.0
- [request](https://npm.io/package/request.md) ^2.79.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.16.0

## Recent versions

- 0.1.12 (latest) — 2017-08-03
- 0.1.11 — 2017-03-04
- 0.1.10 — 2017-02-14
- 0.1.9 — 2017-01-31
- 0.1.8 — 2017-01-23
- 0.1.7 — 2017-01-23
- 0.1.6 — 2017-01-23
- 0.1.5 — 2017-01-19
- 0.1.4 — 2017-01-18
- 0.1.3 — 2017-01-18
- 0.1.2 — 2017-01-18
- 0.1.1 — 2017-01-18
- 0.1.0 — 2017-01-18

## README

## Servify

Microservices the simplest way conceivable.

## Usage

### Create a microservice:

```javascript
const servify = require("servify");

// The service state
let count = 0;

// Starts a microservice with 3 API methods
servify.api(3000, {

    // Squares a number
    square: (x) => x * x,

    // Concats two arrays
    concat: (a, b) => a.concat(b),

    // Increments and returns the counter
    count: () => count++

}).then(() => console.log("servified port 3000"))
```

### Call a microservice from code:

```javascript
const servify = require("servify");

// Builds the API interface from an URL
const api = servify.at("http://localhost:3000");

// Calls API methods like normal lib functions
api.square(2)
    .then(x => console.log(x));

api.concat([1,2], [3,4])
    .then(arr => console.log(arr));

api.count()
    .then(i => console.log(i));
```

### Call a microservice from the browser / request:

```javascript
Just access the url followed by a function call:

http://localhost:3000/square(2)
http://localhost:3000/concat([1,2], [3,4])
http://localhost:3000/count()
```

## Support

This requires ES6 Proxy support, so you need node.js 6 and up. Proxies cannot be polyfilled in earlier versions.

## Why

When all you want is to create a microservice, [Express.js](http://expressjs.com) becomes annoyingly verbose. You have to worry about things like serializing/deserializing JSON, chosing how to format query/param inputs, picking a XHR lib on the client and so on. Servify is a ridiculously thin (50 LOC) lib that just standardizes that boring stuff. To create a microservice, all you need is an object of functions specifying your API. To interact with a service, all you need is its URL. You can then call its functions exactly like you would call a normal lib (except it returns a Promise, obviously).

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