1.0.3 • Published 12 months ago

autana-api-gateway v1.0.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
12 months ago

autana-api-gateway

A minimalist API-Gateway for Node-RED

Install

Run the following command in your Node-RED user directory - typically ~/.node-red

    npm install autana-api-gateway

Information

Before use API Gateway, first configure the rules sending a msg.payload with a JSON like this:

{
   "GET": {
      "/pets/": {
         "actionId": "read all pets"
      },
      "/pets/:petId": {
         "actionId": "read pet"
      }
   },
   "POST": {
      "/pets/": {
         "actionId": "create pet"
      },
      "/pets/:petId": {
         "actionId": "update pet"
      }
   },
   "DELETE": {
      "/pets/:petId": {
         "actionId": "delete pet"
      }
   }
}

The output msg.req contains an autana object like this:

msg.req.autana =

{
   "method": "POST",
   "route": "/pets/:petId",
   "url": "/pets/123",
   "pathParams": {
      "petId": "123"
   },
   "queryParams": {},
   "action": {
      "actionId": "update pet"
   }
}

Then You can take an action filtering by msg.req.autana.action.actionId

exampleFlow

actionId filtering

Remarks

In your main flow, you must connect a http response node as the end of your flow.

Extension

You can add more information to the action when configuring:

Example: Add anActionField, anotherActionField and persistence to the action "read all pets"

{
   "GET": {
      "/pets/": {
         "actionId": "read all pets",
         "anActionField": "foo",
         "anotherActionField": "bar",
         "persistence": {
            "table": "dbo.pets"
         }
      },
      "/pets/:petId": {
         "actionId": "read pet"
      }
   }
}

When receiving a GET to /pets/, msg.req.autana.action will contain this:

{
   "actionId": "read all pets",
   "anActionField": "foo",
   "anotherActionField": "bar",
   "persistence": {
      "table": "dbo.pets"
   }
}
1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago