# README

Gateway using Default Http Pattern

This recipe is a gateway using the defult http pattern which uses JWT, Rate Limiter, and Circuit Breaker.

Circuit Breaker Service:

NameTypeDescription
modestringThe tripping mode: 'a' for contiguous errors, 'b' for errors within a time period, 'c' for contiguous errors within a time period, and 'd' for a probabilistic smart circuit breaker mode. Defaults to mode 'a'
thresholdnumberThe number of errors required for tripping
periodnumberNumber of seconds in which errors have to occur for the circuit breaker to trip. Applies to modes 'b' and 'c'
timeoutnumberNumber of seconds that the circuit breaker will remain tripped. Applies to modes 'a', 'b', 'c'

Rate Limiter

NameTypeDescription
limitstringLimit can be specifed in the format of "limit-period". Valid periods are 'S', 'M' & 'H' to represent Second, Minute & Hour. Example: "10-S" represents 10 request/second

JWT

NameTypeDescription
tokenstringThe raw token
keystringThe key used to sign the token
signingMethodstringThe signing method used (HMAC, ECDSA, RSA, RSAPSS)
issuerstringThe 'iss' standard claim to match against
subjectstringThe 'sub' standard claim to match against
audiencestringThe 'aud' standard claim to match against

Installation

  • Install Go
  • Install the flogo cli

Setup

git clone https://github.com/project-flogo/microgateway
cd microgateway/examples/json/default-http-pattern

Testing

Create the gateway:

flogo create -f flogo.json
cd MyProxy
flogo install github.com/project-flogo/contrib/activity/rest
flogo install github.com/project-flogo/microgateway/activity/circuitbreaker
flogo install github.com/project-flogo/microgateway/activity/jwt
flogo install github.com/project-flogo/microgateway/activity/ratelimiter
flogo build

Start the gateway:

bin/MyProxy

and test below scenario.

In another terminal start the server:

go run main.go -server

Request is successful

Run the following command:

curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oKs"

You should see:

{"category":{"id":0,"name":"string"},"id":1,"name":"sally","photoUrls":["string"],"status":"available","tags":[{"id":0,"name":"string"}]}

JWT token is invalid

Run the following command:

curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oK"

You should see:

{"errorMessage":"","validationMessage":"signature is invalid"}

Rate limit is exceeded

Run the following command faster the 1 per second:

curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oKs"

You should see:

{"status":"Rate Limit Exceeded - The service you have requested is over the allowed limit."}

Circuit breaker tripped

Stop the server and run the following command 6 times:

curl --request GET http://localhost:9096/endpoint -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNYXNobGluZyIsImlhdCI6MTU0NDEzMTYxOCwiZXhwIjoxNTc1NjY3NjE4LCJhdWQiOiJ3d3cubWFzaGxpbmcuaW8iLCJzdWIiOiJ0ZW1wdXNlckBtYWlsLmNvbSJ9.wgunWSIJqieRKsmObATT2VEHMMzkKte6amuUlhc1oKs"

You should see:

{"error":"circuit breaker tripped"}