Skip to content

Latest commit

 

History

History
101 lines (91 loc) · 2.99 KB

README.md

File metadata and controls

101 lines (91 loc) · 2.99 KB

APROXY

An Advanced Application Proxy

Introduction

AProxy (An Advanced Application Proxy) is a way to translate complex and generic REST requests into more simplified and specific requests.

Features:

  • scalable "hot plugging/unplugging" of advanced request proxy/re-write configurations (also called Mappings)
  • advanced url and body generation using GO Templates

Example

The following complex request

POST http://api.com/service/application/challenge_result/_search?search_type=count&pretty
{
"aggs": {
    "most_played_challenges": {
      "terms": {
        "field": "_parent",
        "order" : { "_count" : "desc" }
      }
    }
  }
}

Can be turned into a simple request

GET http://application.com/challenges/popular

By using the following configuration (or Mapping)

{
  "mappings" : {
    "indexer" : {
      "target" : {
        "headers" : {
          "Content-Type" : "application/json; charset=UTF-8"
        },
        "verb" : "POST",
        "uri" : "http://api.com/service/application/challenge_result/_search?search_type=count&pretty",
        "body" : "
        {
          \"aggs\"": {
            \"most_played_challenges\": {
              \"terms\": {
                \"field\" : \"_parent\",
                \"order\" : { \"_count\" : \"desc\" }
              }
            }
          }
        }
      "
      },
      "mapping" : {
        "request.path" : "(?i)^/challenges/popular/?$"
      }
    }
  }
}

Mappings

AProxy mappings take the form of

{
  "mappings" : {
    "<NAME>" : {
      "target" : {
        "headers" : {"<HEADER_NAME>" : "<HEADER_VALUE>"},
        "verb" : "GET|POST|PUT|DELETE|OPTION|HEAD",
        "uri" : "<URI_TEMPLATE>",
        "body" : "<BODY_TEMPLATE>"
      },
      "mapping" : {
        "<PROPERTY_NAME1>" : "<REGULAR_EXPRESSION>"
      }
    }
  }
}

Each mapping has a which is a unique identifier. Every mapping has a target property:

  • headers a list of headers to send to the underlying service
  • verb verb to use in request to the underlying service
  • uri uri to the underlying service, this is a template and not a simple string
  • body body to send to the underlying service, this is a template and not a simple string

Every mapping also has a mapping property, this is a map of property names and regular expressions used to map this particular mapping to incoming requests.

properties available for mappings and templates are:

  • request.method request verb, ex: GET, POST, PUT, OPTION, DELETE, HEAD
  • request.path ex: /twitter/123451
  • request.host ex: www.google.com
  • request.uri raw uri, ex: /twitter/123451?id=4512&ref=sau
  • request.content-length ex: 1024
  • query.xxx always lower-cased, ex: /twitter/123451?id=4512&ref=sau will avail query.id and query.ref
  • header.xxx always lower-cased, ex: header.content-type, header.user-agent