Skip to content

Commit

Permalink
Merge pull request #4624 from irunika/http-matrix-param-support
Browse files Browse the repository at this point in the history
[HTTP] Sample Update for Matrix Parameters
  • Loading branch information
anupama-pathirage authored Feb 8, 2018
2 parents 3f8a558 + de26a6a commit 0c17cca
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/ballerina-by-example/examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ File API
Throw
Try/Catch/Finally
Base Path and Path
Query and Path Param
Query, Path and Matrix Param
Content Based Routing
Header Based Routing
Produces/Consumes
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$ curl "http://localhost:9090/sample/path;a=4;b=5/value1;x=10;y=15?bar=value2"
{
"pathParam": "value1",
"queryParam": "value2",
"matrix": {
"path": "a=4, b=5",
"foo": "x=10, y=15"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ service<http> sample {
// Get QueryParam.
map params = req.getQueryParams();
var bar, _ = (string)params.bar;

// Get Matrix params
map pathMParams = req.getMatrixParams("/sample/path");
var a, _ = (string)pathMParams.a;
var b, _ = (string)pathMParams.b;
string pathMatrixStr = string `a={{a}}, b={{b}}`;
map fooMParams = req.getMatrixParams("/sample/path/" + foo);
var x, _ = (string)fooMParams.x;
var y, _ = (string)fooMParams.y;
string fooMatrixStr = string `x={{x}}, y={{y}}`;
json matrixJson = {"path":pathMatrixStr, "foo":fooMatrixStr};

// Create json payload with the extracted values.
json responseJson = {"pathParam":foo, "queryParam":bar};
json responseJson = {"pathParam":foo, "queryParam":bar, "matrix":matrixJson};
http:OutResponse res = {};
// A util method to set the json payload to the response message.
res.setJsonPayload(responseJson);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Ballerina support extracting values PathParam, QueryParam and MatrixParam.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$ ballerina run query-path-and-matrix-param.bal
ballerina: deploying service(s) in '.../query-path-and-matrix-param.bal'
ballerina: started HTTP/WS server connector 0.0.0.0:9090

0 comments on commit 0c17cca

Please sign in to comment.