From de26a6af0fbd86e5aa40a1554b3f0de0602e85d9 Mon Sep 17 00:00:00 2001 From: irunika Date: Thu, 8 Feb 2018 17:15:50 +0530 Subject: [PATCH] Update ballerina-by-example --- docs/ballerina-by-example/examples.txt | 2 +- .../query-and-path-param.client.sh | 2 -- .../query-and-path-param.description | 1 - .../query-and-path-param.server.sh | 3 --- .../query-and-path-param.client.sh | 9 +++++++++ .../query-path-and-matrix-param.bal} | 14 +++++++++++++- .../query-path-and-matrix-param.description | 1 + .../query-path-and-matrix-param.server.sh | 3 +++ 8 files changed, 27 insertions(+), 8 deletions(-) delete mode 100644 docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.client.sh delete mode 100644 docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.description delete mode 100644 docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.server.sh create mode 100644 docs/ballerina-by-example/examples/query-path-and-matrix-param/query-and-path-param.client.sh rename docs/ballerina-by-example/examples/{query-and-path-param/query-and-path-param.bal => query-path-and-matrix-param/query-path-and-matrix-param.bal} (54%) create mode 100644 docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.description create mode 100644 docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.server.sh diff --git a/docs/ballerina-by-example/examples.txt b/docs/ballerina-by-example/examples.txt index afb500476c9f..c2b7b11dca21 100644 --- a/docs/ballerina-by-example/examples.txt +++ b/docs/ballerina-by-example/examples.txt @@ -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 diff --git a/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.client.sh b/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.client.sh deleted file mode 100644 index e7d7961ecd45..000000000000 --- a/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.client.sh +++ /dev/null @@ -1,2 +0,0 @@ -$ curl http://localhost:9090/sample/path/value1?bar=value2 -{"pathParam": "value1", "queryParam": "value2"} diff --git a/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.description b/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.description deleted file mode 100644 index d36bf53d35b4..000000000000 --- a/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.description +++ /dev/null @@ -1 +0,0 @@ -// Ballerina support extracting values both from PathParam and QueryParam. \ No newline at end of file diff --git a/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.server.sh b/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.server.sh deleted file mode 100644 index 2640b17735f0..000000000000 --- a/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.server.sh +++ /dev/null @@ -1,3 +0,0 @@ -$ ballerina run query-and-path-param.bal -ballerina: deploying service(s) in '.../query-and-path-param.bal' -ballerina: started HTTP/WS server connector 0.0.0.0:9090 \ No newline at end of file diff --git a/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-and-path-param.client.sh b/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-and-path-param.client.sh new file mode 100644 index 000000000000..f55891c8f4e3 --- /dev/null +++ b/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-and-path-param.client.sh @@ -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" + } +} diff --git a/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.bal b/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.bal similarity index 54% rename from docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.bal rename to docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.bal index ed04ee7eebe4..6bc90bfe4bd9 100644 --- a/docs/ballerina-by-example/examples/query-and-path-param/query-and-path-param.bal +++ b/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.bal @@ -11,8 +11,20 @@ service 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); diff --git a/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.description b/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.description new file mode 100644 index 000000000000..f81b95af1d34 --- /dev/null +++ b/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.description @@ -0,0 +1 @@ +// Ballerina support extracting values PathParam, QueryParam and MatrixParam. \ No newline at end of file diff --git a/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.server.sh b/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.server.sh new file mode 100644 index 000000000000..9214dcad72f7 --- /dev/null +++ b/docs/ballerina-by-example/examples/query-path-and-matrix-param/query-path-and-matrix-param.server.sh @@ -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 \ No newline at end of file