0.1.9 • Published 4 years ago

isnode-mod-services v0.1.9

Weekly downloads
35
License
-
Repository
github
Last release
4 years ago

ISNode Services Module

Introduction

This is just a module for the ISNode Framework. To learn how to use the framework, we strongly suggest obtaining a copy of the Hello World example.

The Services module is responsible for loading all installed services and their respective controllers, and for providing an interface for the router to direct requests to the relevent controller.

Configuration

There is currently one attribute that is configurable within the application server's configuration file (config.json) - "allowShutdownFromControllers". If this is set to "true", then it makes the application server (system-wide) shutdown() method available from the "isnode" object that is passed to all of the controllers. If it is set to "false" then the controllers will not be able to access the shutdown() method and will not have any ability to terminate the application server (barring an exception).

  "services": {
    "allowShutdownFromControllers": false
  }

Methods

search(searchObj)

Synchronous Function. Searches for an returns a controller based on serviec name(s), hostname and url (path)

Input Parameters:

  1. searchObj - (Object) Search Object. See example below

Returns: Returns a route object that includes the controller

SearchObj example

 {
   services: ["service1", "service2"],
   hostname: "localhost",
   url: "/web/users/1"
 }

service(name)

Synchronous Function. Returns a service object, given a service name. Using this object you can navigate the service routes (including controllers), database models instantiated against the service and service configuration.

Input Parameters:

  1. name - (String) Name of the service to return.

Returns: Returns a service object

Example

 var helloWorldService = isnode.module("services").service("hello-world");

service(name).cfg()

Synchronous Function. Fetches service configuration object

Input Parameters:

  1. name - (String) Name of the service

Returns: Service configuration object

Example

 var serviceConfig = isnode.module("services").service("hello-world").cfg();

service(name).model.add(modelName, modelObj)

Synchronous Function. Adds a model against a service.

Input Parameters:

  1. name - (String) Name of the service
  2. modelName - (String) Name of the model to add
  3. modelObj - (Object) The model object to add

Returns: Returns true on successful addition of model to service

Example

 // Assume "model" has already been defined
 isnode.module("services").service("hello-world").model.add("test", model);

service(name).model.get(modelName)

Synchronous Function. Fetches a defined model from a service

Input Parameters:

  1. name - (String) Name of the service
  2. modelName - (String) Name of the model to fetch

Returns: Returns the model object

Example

 // Assume "model" has already been defined
 var model = isnode.module("services").service("hello-world").model.get("test");

service(name).url.get(path, options)

Synchronous Function. Takes a controller-relative path and returns application path (including base url)

Input Parameters:

  1. path - (String) Controller-relative path
  2. options - (Object) Child strings of "protocol", "port" and "full". Only need to set protocol and port if full is set as this will return an absolute URL. If full is not set or is set to false it will return the relative path

Returns: Returns a URL (absolute or relative path depending on input)

Example

 // Assume basePath is set to "/test/path"
 var url = isnode.module("services").service("hello-world").url.get("/web/test");
 console.log(url); // Should render "/test/path/web/test"

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.8

5 years ago