autana-api-gateway

1.0.3 • Public • Published

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"
   }
}

Package Sidebar

Install

npm i autana-api-gateway

Weekly Downloads

9

Version

1.0.3

License

Apache-2.0

Unpacked Size

586 kB

Total Files

10

Last publish

Collaborators

  • ggsotillo