Merge pull request #35 from apimesh/api-support

API support
diff --git a/.gitignore b/.gitignore
index 2a8b5f2..64a6349 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,8 @@
 api-gateway-config/target/*
 api-gateway-config/conf.d/includes/resolvers.conf
 *.iml
+
+# No temporary vim files
+*~
+*.swp
+*.swo
diff --git a/README.md b/README.md
index 48b2679..7422d19 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
 
 * [Quick Start](#quick-start)
 * [API](#api)
-  * [Routes](#routes)
+  * [Resources](#resources)
   * [Subscriptions](#subscriptions)
 * [Developer Guide](#developer-guide)
 
@@ -25,16 +25,16 @@
 
 This command starts an API Gateway that subscribes to the Redis instance with the specified host and port. The `REDIS_PASS` variable is optional and is required only when redis needs authentication. 
 
-On startup, the API Gateway looks for pre-existing routes in redis, whose keys are defined as `routes:<namespace>:<route>`, and creates nginx conf files associated with those routes. Then, it listens for any route key changes in redis and updates nginx conf files appropriately. These conf files are stored in the running docker container at `/etc/api-gateway/managed_confs/<namespace>/<route>.conf`.
+On startup, the API Gateway looks for pre-existing resources in redis, whose keys are defined as `resources:<namespace>:<resource>`, and creates nginx conf files associated with those resources. Then, it listens for any resource key changes in redis and updates nginx conf files appropriately. These conf files are stored in the running docker container at `/etc/api-gateway/managed_confs/<namespace>/<resource>.conf`.
 
 
 API
 ==============
 The following endpoints are exposed to port 9000.
 
-## Routes
-#### PUT /routes/{namespace}/{url-encoded-route}
-Create/update and expose a new route on the gateway associated with a namespace and a url-encoded route, with the implementation matching the passed values.
+## Resources
+#### PUT /resources/{namespace}/{url-encoded-resource}
+Create/update and expose a new resource on the gateway associated with a namespace and a url-encoded resource, with the implementation matching the passed values.
 
 _body:_
 ```
@@ -42,50 +42,50 @@
   "gatewayMethod": *(string) The method that you would like your newly exposed API to listen on.
   "backendURL": *(string) The fully qualified URL that you would like your invoke operation to target.
   "backendMethod": (string) The method that you would like the invoke operation to use. If none is supplied, the gatewayMethod will be used.
-  "policies": *(array) A list of policy objects that will be applied during the execution of your route.
+  "policies": *(array) A list of policy objects that will be applied during the execution of your resource.
   "security": (object) An optional json object defining security policies (e.g. {"type": "apikey"} )
 }
 ```
 _Returns:_
 ```
 {
-  "managedUrl": (string) The URL at which you can invoke your newly created route.
+  "managedUrl": (string) The URL at which you can invoke your newly created resource.
 }
 ```
 
-#### GET /routes/{namespace}/{url-encoded-route}
-Get the specified route and return the managed url.
+#### GET /resources/{namespace}/{url-encoded-resource}
+Get the specified resource and return the managed url.
 
 _Returns:_
 ```
 {
-  "managedUrl": (string) The URL at which you can invoke the route.
+  "managedUrl": (string) The URL at which you can invoke the resource.
 }
 ```
 
-#### DELETE /routes/{namespace}/{url-encoded-route}
-Delete the specified route from redis and delete the corresponding conf file.
+#### DELETE /resources/{namespace}/{url-encoded-resource}
+Delete the specified resource from redis and delete the corresponding conf file.
 
 _Returns:_
 ```
-Route deleted.
+Resource deleted.
 ```
 
 #### GET /subscribe
-This is called automatically on gateway startup. It subscribes to route key changes in redis and creates/updates the necessary nginx conf files.
+This is called automatically on gateway startup. It subscribes to resource key changes in redis and creates/updates the necessary nginx conf files.
 
 
 ## Subscriptions
-#### PUT /subscriptions/{namespace}/{url-encoded-route}/{api-key}
-Add/update an api key for a given route. Alternatively, call `PUT /subscriptions/{namespace}/{api-key}` to create an api key for the namespace.
+#### PUT /subscriptions/{namespace}/{url-encoded-resource}/{api-key}
+Add/update an api key for a given resource. Alternatively, call `PUT /subscriptions/{namespace}/{api-key}` to create an api key for the namespace.
 
 _Returns:_
 ```
 Subscription created.
 ```
 
-#### DELETE /subscriptions/{namespace}/{url-encoded-route}/{api-key}
-Delete an api key associated with the route. Alternatively, call DELETE /subscriptions/{namespace}/{api-key} to delete an api key associated with the namespace.
+#### DELETE /subscriptions/{namespace}/{url-encoded-resource}/{api-key}
+Delete an api key associated with the resource. Alternatively, call DELETE /subscriptions/{namespace}/{api-key} to delete an api key associated with the namespace.
 
 _Returns:_
 ```
diff --git a/api-gateway-config/conf.d/management_apis.conf b/api-gateway-config/conf.d/management_apis.conf
index ce3feda..1c13849 100644
--- a/api-gateway-config/conf.d/management_apis.conf
+++ b/api-gateway-config/conf.d/management_apis.conf
@@ -29,19 +29,19 @@
      access_log /var/log/api-gateway/access.log platform;
      error_log /var/log/api-gateway/mgmt_error.log debug;
 
-    location /routes {
+    location /resources {
         access_by_lua_block {
             mgmt = require("management")
             requestMethod = ngx.req.get_method()
             if requestMethod == "GET" then
-                mgmt.getRoute()
+                mgmt.getResource()
             elseif requestMethod == "PUT" then
-                mgmt.addRoute()
+                mgmt.addResource()
             elseif requestMethod == "POST" then
                 ngx.status = 400
                 ngx.say("Use PUT")
             elseif requestMethod == "DELETE" then
-                mgmt.deleteRoute()
+                mgmt.deleteResource()
             else
                 ngx.status = 400
                 ngx.say("Invalid verb")
diff --git a/api-gateway-config/scripts/lua/lib/filemgmt.lua b/api-gateway-config/scripts/lua/lib/filemgmt.lua
index 5cb504b..2980a46 100644
--- a/api-gateway-config/scripts/lua/lib/filemgmt.lua
+++ b/api-gateway-config/scripts/lua/lib/filemgmt.lua
@@ -28,22 +28,22 @@
 
 local _M = {}
 
---- Create/overwrite Nginx Conf file for given route
+--- Create/overwrite Nginx Conf file for given resource
 -- @param baseConfDir
 -- @param namespace
 -- @param gatewayPath
--- @param routeObj
+-- @param resourceObj
 -- @return fileLocation location of created/updated conf file
-function _M.createRouteConf(baseConfDir, namespace, gatewayPath, routeObj)
-  routeObj = utils.serializeTable(cjson.decode(routeObj))
+function _M.createResourceConf(baseConfDir, namespace, gatewayPath, resourceObj)
+  resourceObj = utils.serializeTable(cjson.decode(resourceObj))
   local prefix = utils.concatStrings({"\tinclude /etc/api-gateway/conf.d/commons/common-headers.conf;\n",
                                       "\tset $upstream https://172.17.0.1;\n",
                                       "\tset $namespace ", namespace, ";\n",
                                       "\tset $gatewayPath ", gatewayPath, ";\n\n"})
-  -- Set route headers and mapping by calling routing.processCall()
-  local outgoingRoute = utils.concatStrings({"\taccess_by_lua_block {\n",
+  -- Set resource headers and mapping by calling routing.processCall()
+  local outgoingResource = utils.concatStrings({"\taccess_by_lua_block {\n",
                                              "\t\tlocal routing = require \"routing\"\n",
-                                             "\t\trouting.processCall(", routeObj, ")\n",
+                                             "\t\trouting.processCall(", resourceObj, ")\n",
                                              "\t}\n\n",
                                              "\tproxy_pass $upstream;\n"})
 
@@ -58,7 +58,7 @@
   end
   local location = utils.concatStrings({"location /api/", namespace, "/", ngx.unescape_uri(gatewayPath), " {\n",
                                         prefix,
-                                        outgoingRoute,
+                                        outgoingResource,
                                         "}\n"})
   file:write(location)
   file:close()
@@ -70,12 +70,12 @@
 end
 
 
---- Delete Ngx conf file for given route
+--- Delete Ngx conf file for given resource
 -- @param baseConfDir
 -- @param namespace
 -- @param gatewayPath
 -- @return fileLocation location of deleted conf file
-function _M.deleteRouteConf(baseConfDir, namespace, gatewayPath)
+function _M.deleteResourceConf(baseConfDir, namespace, gatewayPath)
   local fileLocation = utils.concatStrings({baseConfDir, namespace, "/", gatewayPath, ".conf"})
   os.execute(utils.concatStrings({"rm -f ", fileLocation}))
   -- reload nginx to refresh conf files
diff --git a/api-gateway-config/scripts/lua/lib/redis.lua b/api-gateway-config/scripts/lua/lib/redis.lua
index 425a3dc..8754aef 100644
--- a/api-gateway-config/scripts/lua/lib/redis.lua
+++ b/api-gateway-config/scripts/lua/lib/redis.lua
@@ -27,6 +27,7 @@
 local utils = require "lib/utils"
 local logger = require "lib/logger"
 
+local REDIS_FIELD = "resources"
 local BASE_CONF_DIR = "/etc/api-gateway/managed_confs/"
 
 local _M = {}
@@ -36,8 +37,7 @@
 -- @param port
 -- @param password
 -- @param timeout
--- @param ngx
-function _M.init(host, port, password, timeout, ngx)
+function _M.init(host, port, password, timeout)
   local redis = require "resty.redis"
   local red   = redis:new()
   red:set_timeout(timeout)
@@ -65,8 +65,7 @@
 
 --- Add current redis connection in the ngx_lua cosocket connection pool
 -- @param red
--- @param ngx
-function _M.close(red, ngx)
+function _M.close(red)
   -- put it into the connection pool of size 100, with 10 seconds max idle time
   local ok, err = red:set_keepalive(10000, 100)
   if not ok then
@@ -76,117 +75,104 @@
   end
 end
 
---- Generate Redis object for route
+--- Generate Redis object for resource
 -- @param red
 -- @param key
 -- @param gatewayMethod
 -- @param backendUrl
 -- @param backendMethod
+-- @param apiId
 -- @param policies
--- @param ngx
-function _M.generateRouteObj(red, key, gatewayMethod, backendUrl, backendMethod, policies, security, ngx)
-  local routeObj = _M.getRoute(red, key, "route", ngx)
-  if routeObj == nil then
-    local newRoute = {
-      [gatewayMethod] = {
-        backendUrl    = backendUrl,
-        backendMethod = backendMethod,
-        policies      = policies,
+-- @param security
+function _M.generateResourceObj(red, key, gatewayMethod, backendUrl, backendMethod, apiId, policies, security)
+  local newResource
+  local resourceObj = _M.getResource(red, key, REDIS_FIELD)
+  if resourceObj == nil then
+    newResource = {
+      operations = {
+        [gatewayMethod] = {
+          backendUrl = backendUrl,
+          backendMethod = backendMethod,
+        }
       }
     }
-    if security then
-      newRoute[gatewayMethod].security = security
-    end
-    return cjson.encode(newRoute)
   else
-    local decoded = cjson.decode(routeObj)
-    decoded[gatewayMethod] = {
-      backendUrl    = backendUrl,
+    newResource = cjson.decode(resourceObj)
+    newResource.operations[gatewayMethod] = {
+      backendUrl = backendUrl,
       backendMethod = backendMethod,
-      policies      = policies
     }
-    if security then
-      decoded[gatewayMethod].security = security
-    end
-    return cjson.encode(decoded)
   end
+  if apiId then
+    newResource.apiId = apiId
+  end
+  if policies then
+    newResource.operations[gatewayMethod].policies = policies
+  end
+  if security then
+    newResource.operations[gatewayMethod].security = security
+  end
+  return cjson.encode(newResource)
 end
 
---- Create/update route in redis
+--- Create/update resource in redis
 -- @param red
 -- @param key
 -- @param field
--- @param routeObj
--- @param ngx
-function _M.createRoute(red, key, field, routeObj, ngx)
-  -- Add/update route to redis
-  local ok, err = red:hset(key, field, routeObj)
+-- @param resourceObj
+function _M.createResource(red, key, field, resourceObj)
+  -- Add/update resource to redis
+  local ok, err = red:hset(key, field, resourceObj)
   if not ok then
     ngx.status = 500
-    ngx.say(utils.concatStrings({"Failed adding Route to redis: ", err}))
+    ngx.say(utils.concatStrings({"Failed adding Resource to redis: ", err}))
     ngx.exit(ngx.status)
   end
 end
 
---- Get route in redis
+--- Get resource in redis
 -- @param red
 -- @param key
 -- @param field
--- @param ngx
--- @return routeObj
-function _M.getRoute(red, key, field, ngx)
-  local routeObj, err = red:hget(key, field)
-  if not routeObj then
+-- @return resourceObj
+function _M.getResource(red, key, field)
+  local resourceObj, err = red:hget(key, field)
+  if not resourceObj then
     ngx.status = 500
-    ngx.say("Error getting route: ", err)
+    ngx.say("Error getting resource: ", err)
     ngx.exit(ngx.status)
   end
 
-  -- return nil if route doesn't exist
-  if routeObj == ngx.null then
+  -- return nil if resource doesn't exist
+  if resourceObj == ngx.null then
     return nil
   end
 
-  -- Get routeObj from redis using redisKey
-  local args = ngx.req.get_uri_args()
-  local requestVerb = nil
-  for k, v in pairs(args) do
-    if k == "verb" then
-      requestVerb = v
-    end
-  end
-
-  if requestVerb == nil then
-    return routeObj
-  else
-    routeObj = cjson.decode(routeObj)
-    return cjson.encode(routeObj[requestVerb])
-  end
+  return resourceObj
 end
 
---- Delete route int redis
+--- Delete resource int redis
 -- @param red
 -- @param key
 -- @param field
--- @param ngx
-function _M.deleteRoute(red, key, field, ngx)
-  local routeObj, err = red:hget(key, field)
-  if not routeObj then
+function _M.deleteResource(red, key, field)
+  local resourceObj, err = red:hget(key, field)
+  if not resourceObj then
     ngx.status = 500
-    ngx.say("Error deleting route: ", err)
+    ngx.say("Error deleting resource: ", err)
     ngx.exit(ngx.status)
   end
 
-  if routeObj == ngx.null then
+  if resourceObj == ngx.null then
     ngx.status = 404
-    ngx.say("Route doesn't exist.")
+    ngx.say("Resource doesn't exist.")
     ngx.exit(ngx.status)
   end
 
   local ok, err = red:del(key)
   if not ok then
     ngx.status = 500
-    ngx.say("Error deleing route: ", err)
+    ngx.say("Error deleing resource: ", err)
     ngx.exit(ngx.status)
   end
 end
@@ -194,10 +180,9 @@
 --- Create/update subscription/apikey in redis
 -- @param red
 -- @param key
--- @param ngx
-function _M.createSubscription(red, key, ngx)
+function _M.createSubscription(red, key)
   -- Add/update a subscription key to redis
-  local ok, err = red:set (key, "")
+  local ok, err = red:set(key, "")
   if not ok then
     ngx.status = 500
     ngx.say(utils.concatStrings({"Failed adding subscription to redis: ", err}))
@@ -208,8 +193,7 @@
 --- Delete subscription/apikey int redis
 -- @param red
 -- @param key
--- @param ngx
-function _M.deleteSubscription(red, key, ngx)
+function _M.deleteSubscription(red, key)
   local ok, err = red:del(key, "subscriptions")
   if not ok then
     ngx.status = 500
@@ -220,10 +204,9 @@
 
 --- Subscribe to redis
 -- @param redisSubClient the redis client that is listening for the redis key changes
--- @param redisGetClient the redis client that gets the changed route to update the conf file
--- @param ngx
-function _M.subscribe(redisSubClient, redisGetClient, ngx)
-  -- create conf files for existing routes in redis
+-- @param redisGetClient the redis client that gets the changed resource to update the conf file
+function _M.subscribe(redisSubClient, redisGetClient)
+  -- create conf files for existing resources in redis
   syncWithRedis(redisGetClient, ngx)
 
   -- enable keyspace notifications
@@ -234,7 +217,7 @@
     ngx.exit(ngx.status)
   end
 
-  local ok, err = redisSubClient:psubscribe("__keyspace@0__:routes:*:*")
+  local ok, err = redisSubClient:psubscribe("__keyspace@0__:resources:*:*")
   if not ok then
     ngx.status = 500
     ngx.say("Subscribe error: ", err)
@@ -248,11 +231,10 @@
   ngx.exit(ngx.status)
 end
 
---- Sync with redis on startup and create conf files for routes that are already in redis
+--- Sync with redis on startup and create conf files for resources that are already in redis
 -- @param red
--- @param ngx
-function syncWithRedis(red, ngx)
-  logger.info("\nCreating nginx conf files for existing routes...")
+function syncWithRedis(red)
+  logger.info("\nCreating nginx conf files for existing resources...")
   local redisKeys, err = red:keys("*")
   if not redisKeys then
     ngx.status = 500
@@ -260,18 +242,18 @@
     ngx.exit(ngx.status)
   end
 
-  -- Find all redis keys with "routes:*:*"
-  local routesExist = false
+  -- Find all redis keys with "resources:*:*"
+  local resourcesExist = false
   for k, redisKey in pairs(redisKeys) do
     local index = 1
     local namespace = ""
     local gatewayPath = ""
     for word in string.gmatch(redisKey, '([^:]+)') do
       if index == 1 then
-        if word ~= "routes" then
+        if word ~= "resources" then
           break
         else
-          routesExist = true
+          resourcesExist = true
           index = index + 1
         end
       else
@@ -280,25 +262,24 @@
         elseif index == 3 then
           gatewayPath = word
           -- Create new conf file
-          local routeObj = _M.getRoute(red, redisKey, "route", ngx)
-          local fileLocation = filemgmt.createRouteConf(BASE_CONF_DIR, namespace, ngx.escape_uri(gatewayPath), routeObj)
+          local resourceObj = _M.getResource(red, redisKey, REDIS_FIELD)
+          local fileLocation = filemgmt.createResourceConf(BASE_CONF_DIR, namespace, ngx.escape_uri(gatewayPath), resourceObj)
           logger.info(utils.concatStrings({"Updated file: ", fileLocation}))
         end
         index = index + 1
       end
     end
   end
-  if routesExist == false then
-    logger.info("No existing routes.")
+  if resourcesExist == false then
+    logger.info("No existing resources.")
   end
 end
 
 --- Subscribe helper method
 -- Starts a while loop that listens for key changes in redis
 -- @param redisSubClient the redis client that is listening for the redis key changes
--- @param redisGetClient the redis client that gets the changed route to update the conf file
--- @param ngx
-function subscribe(redisSubClient, redisGetClient, ngx)
+-- @param redisGetClient the redis client that gets the changed resource to update the conf file
+function subscribe(redisSubClient, redisGetClient)
   while true do
     local res, err = redisSubClient:read_reply()
     if not res then
@@ -323,14 +304,14 @@
         index = index + 1
       end
 
-      local routeObj = _M.getRoute(redisGetClient, redisKey, "route", ngx)
+      local resourceObj = _M.getResource(redisGetClient, redisKey, REDIS_FIELD)
 
-      if routeObj == nil then
-        local fileLocation = filemgmt.deleteRouteConf(BASE_CONF_DIR, namespace, ngx.escape_uri(gatewayPath))
+      if resourceObj == nil then
+        local fileLocation = filemgmt.deleteResourceConf(BASE_CONF_DIR, namespace, ngx.escape_uri(gatewayPath))
         logger.info(utils.concatStrings({"Redis key deleted: ", redisKey}))
         logger.info(utils.concatStrings({"Deleted file: ", fileLocation}))
       else
-        local fileLocation = filemgmt.createRouteConf(BASE_CONF_DIR, namespace, ngx.escape_uri(gatewayPath), routeObj)
+        local fileLocation = filemgmt.createResourceConf(BASE_CONF_DIR, namespace, ngx.escape_uri(gatewayPath), resourceObj)
         logger.info(utils.concatStrings({"Redis key updated: ", redisKey}))
         logger.info(utils.concatStrings({"Updated file: ", fileLocation}))
       end
@@ -341,8 +322,8 @@
 
 
 --- Unsubscribe from redis
-function _M.unsubscribe(red, ngx)
-  local ok, err = red:unsubscribe("__keyspace@0__:routes:*:*")
+function _M.unsubscribe(red)
+  local ok, err = red:unsubscribe("__keyspace@0__:resources:*:*")
   if not ok then
     ngx.status = 500
     ngx.say("Unsubscribe error: ", err)
diff --git a/api-gateway-config/scripts/lua/lib/resty/limit/req.lua b/api-gateway-config/scripts/lua/lib/resty/limit/req.lua
index 3c9b882..eeec626 100644
--- a/api-gateway-config/scripts/lua/lib/resty/limit/req.lua
+++ b/api-gateway-config/scripts/lua/lib/resty/limit/req.lua
@@ -130,7 +130,7 @@
         rds.port = rds.port or 6379
         rds.pass = rds.pass or nil
 
-        cfg.conn = redis.init(rds.host, rds.port, rds.pass, rds.timeout, ngx)
+        cfg.conn = redis.init(rds.host, rds.port, rds.pass, rds.timeout)
     end
 
     local conn = cfg.conn
diff --git a/api-gateway-config/scripts/lua/management.lua b/api-gateway-config/scripts/lua/management.lua
index c35561a..2c7c785 100644
--- a/api-gateway-config/scripts/lua/management.lua
+++ b/api-gateway-config/scripts/lua/management.lua
@@ -19,7 +19,7 @@
 --   DEALINGS IN THE SOFTWARE.
 
 --- @module management
--- Defines and exposes a lightweight API management to create and remove routes in the running API Gateway
+-- Defines and exposes a lightweight API management to create and remove resources in the running API Gateway
 -- @author Alex Song (songs)
 
 local cjson = require "cjson"
@@ -32,15 +32,18 @@
 local REDIS_PORT = os.getenv("REDIS_PORT")
 local REDIS_PASS = os.getenv("REDIS_PASS")
 
+local REDIS_FIELD = "resources"
+
 local BASE_CONF_DIR = "/etc/api-gateway/managed_confs/"
 
 local _M = {}
 
---- Add/update a route to redis and create/update an nginx conf file given PUT JSON body
+--- Add/update a resource to redis and create/update an nginx conf file given PUT JSON body
 --
--- PUT http://0.0.0.0:9000/routes/<namespace>/<url-encoded-route>
+-- PUT http://0.0.0.0:9000/resources/<namespace>/<url-encoded-resource>
 -- Example PUT JSON body:
 -- {
+--      "api": "12345"
 --      "gatewayMethod": "GET",
 --      "backendURL": "http://openwhisk.ng.bluemix.net/guest/action?blocking=true",
 --      "backendMethod": "POST",
@@ -50,7 +53,7 @@
 --      }
 --  }
 --
-function _M.addRoute()
+function _M.addResource()
   -- Read in the PUT JSON Body
   ngx.req.read_body()
   local args = ngx.req.get_post_args()
@@ -62,20 +65,13 @@
   -- Convert json into Lua table
   local decoded = convertJSONBody(args)
 
-  -- Error handling for correct fields in the request body
+  -- Error handling for required fields in the request body
   local gatewayMethod = decoded.gatewayMethod
   if not gatewayMethod then
     ngx.status = 400
     ngx.say("Error: \"gatewayMethod\" missing from request body.")
     ngx.exit(ngx.status)
   end
-  local policies = decoded.policies
-  if not policies then
-    ngx.status = 400
-    ngx.say("Error: \"policies\" missing from request body.")
-    ngx.exit(ngx.status)
-  end
-  local security = decoded.security
   local backendUrl = decoded.backendURL
   if not backendUrl then
     ngx.status = 400
@@ -84,22 +80,26 @@
   end
   -- Use gatewayMethod by default or usebackendMethod if specified
   local backendMethod = decoded and decoded.backendMethod or gatewayMethod
+  -- apiId, policies, security fields are optional
+  local apiId = decoded.apiId
+  local policies = decoded.policies
+  local security = decoded.security
 
   local requestURI = string.gsub(ngx.var.request_uri, "?.*", "")
   local list = parseRequestURI(requestURI)
   local namespace = list[2]
   local gatewayPath = list[3]
-  local redisKey = utils.concatStrings({list[1], ":", namespace, ":", ngx.unescape_uri(gatewayPath)})
+  local redisKey = utils.concatStrings({"resources", ":", namespace, ":", ngx.unescape_uri(gatewayPath)})
 
   -- Open connection to redis or use one from connection pool
-  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000, ngx)
+  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
 
-  local routeObj = redis.generateRouteObj(red, redisKey, gatewayMethod, backendUrl, backendMethod, policies, security, ngx)
-  redis.createRoute(red, redisKey, "route", routeObj, ngx)
-  filemgmt.createRouteConf(BASE_CONF_DIR, namespace, gatewayPath, routeObj)
+  local resourceObj = redis.generateResourceObj(red, redisKey, gatewayMethod, backendUrl, backendMethod, apiId, policies, security)
+  redis.createResource(red, redisKey, REDIS_FIELD, resourceObj)
+  filemgmt.createResourceConf(BASE_CONF_DIR, namespace, gatewayPath, resourceObj)
 
   -- Add current redis connection in the ngx_lua cosocket connection pool
-  redis.close(red, ngx)
+  redis.close(red)
 
   ngx.status = 200
   ngx.header.content_type = "application/json; charset=utf-8"
@@ -112,14 +112,11 @@
   ngx.exit(ngx.status)
 end
 
---- Get route from redis
+--- Get resource from redis
 --
--- Use optional query parameter, verb, to specify the verb of the route to get
--- Default behavior is to get all the verbs for that route
+-- GET http://0.0.0.0:9000/resources/<namespace>/<url-encoded-resource>
 --
--- GET http://0.0.0.0:9000/routes/<namespace>/<url-encoded-route>?verb="<verb>"
---
-function _M.getRoute()
+function _M.getResource()
   local requestURI = string.gsub(ngx.var.request_uri, "?.*", "")
   local list = parseRequestURI(requestURI)
   local namespace = list[2]
@@ -127,22 +124,30 @@
   local redisKey = utils.concatStrings({list[1], ":", namespace, ":", ngx.unescape_uri(gatewayPath)})
 
   -- Initialize and connect to redis
-  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000, ngx)
+  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
 
-  local routeObj = redis.getRoute(red, redisKey, "route", ngx)
-  if routeObj == nil then
+  local resourceObj = redis.getResource(red, redisKey, REDIS_FIELD)
+  if resourceObj == nil then
     ngx.status = 404
-    ngx.say("Route doesn't exist.")
+    ngx.say("Resource doesn't exist.")
     ngx.exit(ngx.status)
   end
 
   -- Add current redis connection in the ngx_lua cosocket connection pool
-  redis.close(red, ngx)
+  redis.close(red)
+
+  -- Get available operations for the given resource
+  resourceObj = cjson.decode(resourceObj)
+  local operations = {}
+  for k in pairs(resourceObj.operations) do
+    operations[#operations+1] = k
+  end
 
   ngx.status = 200
   ngx.header.content_type = "application/json; charset=utf-8"
   local managedUrlObj = {
-    managedUrl = utils.concatStrings({"http://0.0.0.0/api/", namespace, "/", gatewayPath})
+    managedUrl = utils.concatStrings({"http://0.0.0.0/api/", namespace, "/", gatewayPath}),
+    availableOperations = operations
   }
   local managedUrlObj = cjson.encode(managedUrlObj)
   managedUrlObj = managedUrlObj:gsub("\\", "")
@@ -150,11 +155,11 @@
   ngx.exit(ngx.status)
 end
 
---- Delete route from redis
+--- Delete resource from redis
 --
--- DELETE http://0.0.0.0:9000/routes/<namespace>/<url-encoded-route>
+-- DELETE http://0.0.0.0:9000/resources/<namespace>/<url-encoded-resource>
 --
-function _M.deleteRoute()
+function _M.deleteResource()
   local requestURI = string.gsub(ngx.var.request_uri, "?.*", "")
   local list = parseRequestURI(requestURI)
   local namespace = list[2]
@@ -162,19 +167,19 @@
   local redisKey = utils.concatStrings({list[1], ":", namespace, ":", ngx.unescape_uri(gatewayPath)})
 
   -- Initialize and connect to redis
-  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000, ngx)
+  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
 
-  -- Return if route doesn't exist
-  redis.deleteRoute(red, redisKey, "route", ngx)
+  -- Return if resource doesn't exist
+  redis.deleteResource(red, redisKey, REDIS_FIELD)
 
   -- Delete conf file
-  filemgmt.deleteRouteConf(BASE_CONF_DIR, namespace, gatewayPath)
+  filemgmt.deleteResourceConf(BASE_CONF_DIR, namespace, gatewayPath)
 
   -- Add current redis connection in the ngx_lua cosocket connection pool
-  redis.close(red, ngx)
+  redis.close(red)
 
   ngx.status = 200
-  ngx.say("Route deleted.")
+  ngx.say("Resource deleted.")
   ngx.exit(ngx.status)
 end
 
@@ -184,11 +189,11 @@
 --
 function _M.subscribe()
   -- Initialize and connect to redis
-  local redisSubClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 600000, ngx)
-  local redisGetClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000, ngx)
+  local redisSubClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 600000)
+  local redisGetClient = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
 
   logger.info(utils.concatStrings({"\nConnected to redis at ", REDIS_HOST, ":", REDIS_PORT}))
-  redis.subscribe(redisSubClient, redisGetClient, ngx)
+  redis.subscribe(redisSubClient, redisGetClient)
 
   ngx.exit(200)
 end
@@ -199,16 +204,16 @@
 --
 function _M.unsubscribe()
   -- Initialize and connect to redis
-  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000, ngx)
-  redis.unsubscribe(red, ngx)
+  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
+  redis.unsubscribe(red)
 
   ngx.status = 200
-  ngx.say("Unsubscribed to channel routes")
+  ngx.say("Unsubscribed to channel resources")
   ngx.exit(ngx.status)
 end
 
 --- Add an apikey/subscription to redis
--- PUT http://0.0.0.0:9000/subscriptions/<namespace>/<url-encoded-route>/<key>
+-- PUT http://0.0.0.0:9000/subscriptions/<namespace>/<url-encoded-resource>/<key>
 --  where list[1] = prefix, list[2] = namespace, list[3] = gatewayPath, list[4] = key
 ------ or
 -- PUT http://0.0.0.0:9000/subscriptions/<namespace>/<key>
@@ -224,12 +229,12 @@
   end
 
   -- Open connection to redis or use one from connection pool
-  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000, ngx)
+  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
 
-  redis.createSubscription(red, redisKey, ngx)
+  redis.createSubscription(red, redisKey)
 
   -- Add current redis connection in the ngx_lua cosocket connection pool
-  redis.close(red, ngx)
+  redis.close(red)
 
   ngx.status = 200
   ngx.say("Subscription created.")
@@ -237,7 +242,7 @@
 end
 
 --- Delete apikey/subscription from redis
--- DELETE http://0.0.0.0:9000/subscriptions/<namespace>/<url-encoded-route>/<key>
+-- DELETE http://0.0.0.0:9000/subscriptions/<namespace>/<url-encoded-resource>/<key>
 --  where list[1] = prefix, list[2] = namespace, list[3] = gatewayPath, list[4] = key
 ------ or
 -- DELETE http://0.0.0.0:9000/subscriptions/<namespace>/<key>
@@ -253,13 +258,13 @@
   end
 
   -- Initialize and connect to redis
-  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000, ngx)
+  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
 
   -- Return if subscription doesn't exist
-  redis.deleteSubscription(red, redisKey, ngx)
+  redis.deleteSubscription(red, redisKey)
 
   -- Add current redis connection in the ngx_lua cosocket connection pool
-  redis.close(red, ngx)
+  redis.close(red)
 
   ngx.status = 200
   ngx.say("Subscription deleted.")
@@ -277,7 +282,7 @@
   end
   if not list[1] or not list[2] then
     ngx.status = 400
-    ngx.say("Error: Request path should be \"/routes/<namespace>/<url-encoded-route>\"")
+    ngx.say("Error: Request path should be \"/resources/<namespace>/<url-encoded-resource>\"")
     ngx.exit(ngx.status)
   end
 
diff --git a/api-gateway-config/scripts/lua/policies/rateLimit.lua b/api-gateway-config/scripts/lua/policies/rateLimit.lua
index 3536bf4..23d4836 100644
--- a/api-gateway-config/scripts/lua/policies/rateLimit.lua
+++ b/api-gateway-config/scripts/lua/policies/rateLimit.lua
@@ -40,7 +40,7 @@
      k = ngx.var.namespace
    elseif obj.field == 'apikey' then
      k = utils.concatStrings({ngx.var.namespace, '_', ngx.var['http_x_api_key']})
-   elseif obj.field == 'route' then
+   elseif obj.field == 'resource' then
      k = utils.concatStrings({ngx.var.namespace, '_', ngx.var.gatewayPath})
    end
 
diff --git a/api-gateway-config/scripts/lua/policies/security.lua b/api-gateway-config/scripts/lua/policies/security.lua
index 38f4a2c..693f267 100644
--- a/api-gateway-config/scripts/lua/policies/security.lua
+++ b/api-gateway-config/scripts/lua/policies/security.lua
@@ -34,7 +34,7 @@
 
 function validateAPIKey(namespace, gatewayPath, apiKey)
   -- Open connection to redis or use one from connection pool
-  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000, ngx)
+  local red = redis.init(REDIS_HOST, REDIS_PORT, REDIS_PASS, 1000)
 
   local k = utils.concatStrings({'subscriptions:', tostring(namespace), ':', tostring(gatewayPath), ':', tostring(apiKey)})
   local exists, err = red:exists(k)
diff --git a/api-gateway-config/scripts/lua/routing.lua b/api-gateway-config/scripts/lua/routing.lua
index 87b99d9..17ec999 100644
--- a/api-gateway-config/scripts/lua/routing.lua
+++ b/api-gateway-config/scripts/lua/routing.lua
@@ -35,7 +35,7 @@
 local _M = {}
 
 --- Main function that handles parsing of invocation details and carries out implementation
--- @param obj Lua table object containing implementation details for the given route
+-- @param obj Lua table object containing implementation details for the given resource
 -- {
 --   {{GatewayMethod (GET / PUT / POST / DELETE)}} = {
 --      "backendMethod": (GET / PUT / POST / DELETE) - Method to use for invocation (if different from gatewayMethod),
@@ -46,7 +46,8 @@
 function processCall(obj)
   local verb = ngx.req.get_method()
   local found = false
-  for k, v in pairs(obj) do
+  local operations = obj.operations
+  for k, v in pairs(operations) do
     if k == verb then
       -- Check if auth is required
       if (v.security and string.lower(v.security.type) == 'apikey') then
@@ -64,7 +65,9 @@
       if v.backendMethod ~= nil then
         setVerb(v.backendMethod)
       end
-      parsePolicies(v.policies)
+      if v.policies ~= nil then
+        parsePolicies(v.policies)
+      end
       found = true
       break
     end
@@ -76,7 +79,7 @@
 end
 
 --- Function to read the list of policies and send implementation to the correct backend
--- @param obj List of policies containing a type and value field. This function reads the type field and routes it appropriately.
+-- @param obj List of policies containing a type and value field. This function reads the type field and resources it appropriately.
 function parsePolicies(obj)
   for k, v in pairs (obj) do
     if v.type == 'reqMapping' then
@@ -103,4 +106,4 @@
 
 _M.processCall = processCall
 
-return _M
\ No newline at end of file
+return _M