0.5.3 • Published 7 years ago

nameless-js v0.5.3

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

Build Status

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!

npm i --save nameless-js
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.

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

Api

Server

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

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.

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

Client

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)
0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago