From 332ca061f09dd85fc34ca9226c5bc45298fd5c0c Mon Sep 17 00:00:00 2001 From: Nils Lundquist Date: Fri, 27 Sep 2019 10:15:15 -0600 Subject: [PATCH 1/2] add beforeSend anchor to docs --- data/url/url.js | 1 + 1 file changed, 1 insertion(+) diff --git a/data/url/url.js b/data/url/url.js index 5a81a2ec..d4f00ff1 100644 --- a/data/url/url.js +++ b/data/url/url.js @@ -218,6 +218,7 @@ var urlBehavior = behavior("data/url", function(baseConnection) { * ``` * This can be particularly useful for passing a handler for the [can-ajax beforeSend] hook. * + * * The [can-ajax beforeSend] hook can also be passed for all request methods. This can be useful when * attaching a session token header to a request: * From ca61d292bb249f09c4042eb913136af0e82d179c Mon Sep 17 00:00:00 2001 From: Nils Lundquist Date: Fri, 27 Sep 2019 19:47:03 -0600 Subject: [PATCH 2/2] add codepens for all url object config examples --- data/url/beforeSend-all.html | 69 +++++++++++++++++++++++++ data/url/custom-request.html | 89 ++++++++++++++++++++++++++++++++ data/url/plain-endpoints.html | 96 +++++++++++++++++++++++++++++++++++ data/url/request-params.html | 85 +++++++++++++++++++++++++++++++ data/url/resource-param.html | 83 ++++++++++++++++++++++++++++++ data/url/url.js | 88 -------------------------------- data/url/url.url.md | 53 +++++++++++++++++++ 7 files changed, 475 insertions(+), 88 deletions(-) create mode 100644 data/url/beforeSend-all.html create mode 100644 data/url/custom-request.html create mode 100644 data/url/plain-endpoints.html create mode 100644 data/url/request-params.html create mode 100644 data/url/resource-param.html create mode 100644 data/url/url.url.md diff --git a/data/url/beforeSend-all.html b/data/url/beforeSend-all.html new file mode 100644 index 00000000..057c9f79 --- /dev/null +++ b/data/url/beforeSend-all.html @@ -0,0 +1,69 @@ + + + diff --git a/data/url/custom-request.html b/data/url/custom-request.html new file mode 100644 index 00000000..a05c52f1 --- /dev/null +++ b/data/url/custom-request.html @@ -0,0 +1,89 @@ + + + diff --git a/data/url/plain-endpoints.html b/data/url/plain-endpoints.html new file mode 100644 index 00000000..e96bf0c5 --- /dev/null +++ b/data/url/plain-endpoints.html @@ -0,0 +1,96 @@ + + + diff --git a/data/url/request-params.html b/data/url/request-params.html new file mode 100644 index 00000000..1a363880 --- /dev/null +++ b/data/url/request-params.html @@ -0,0 +1,85 @@ + + + diff --git a/data/url/resource-param.html b/data/url/resource-param.html new file mode 100644 index 00000000..9fbe75e9 --- /dev/null +++ b/data/url/resource-param.html @@ -0,0 +1,83 @@ + + + diff --git a/data/url/url.js b/data/url/url.js index d4f00ff1..10fa2bd1 100644 --- a/data/url/url.js +++ b/data/url/url.js @@ -159,94 +159,6 @@ var urlBehavior = behavior("data/url", function(baseConnection) { return behavior; }); -/** - * @property {String|Object} can-connect/data/url/url.url url - * @parent can-connect/data/url/url.option - * - * Specify the url and methods that should be used for the "Data Methods". - * - * @option {String} If a string is provided, it's assumed to be a RESTful interface. For example, - * if the following is provided: - * - * ``` - * url: "/services/todos" - * ``` - * - * ... the following methods and requests are used: - * - * - `getListData` - `GET /services/todos` - * - `getData` - `GET /services/todos/{id}` - * - `createData` - `POST /services/todos` - * - `updateData` - `PUT /services/todos/{id}` - * - `destroyData` - `DELETE /services/todos/{id}` - * - * @option {Object} If an object is provided, it can customize each method and URL directly - * like: - * - * ```js - * url: { - * getListData: "GET /services/todos", - * getData: "GET /services/todo/{id}", - * createData: "POST /services/todo", - * updateData: "PUT /services/todo/{id}", - * destroyData: "DELETE /services/todo/{id}" - * } - * ``` - * - * You can provide a `resource` property that works like providing `url` as a string, but overwrite - * other values like: - * - * ```js - * url: { - * resource: "/services/todo", - * getListData: "GET /services/todos" - * } - * ``` - * - * You can also customize per-method the parameters passed to the [can-connect/data/url/url.ajax ajax implementation], like: - * ```js - * url: { - * resource: "/services/todos", - * getListData: { - * url: "/services/todos", - * type: "GET", - * beforeSend: () => { - * return fetch('/services/context').then(processContext); - * } - * } - * } - * ``` - * This can be particularly useful for passing a handler for the [can-ajax beforeSend] hook. - * - * - * The [can-ajax beforeSend] hook can also be passed for all request methods. This can be useful when - * attaching a session token header to a request: - * - * ```js - * url: { - * resource: "/services/todos", - * beforeSend: (xhr) => { - * xhr.setRequestHeader('Authorization', `Bearer: ${Session.current.token}`); - * } - * } - * ``` - * - * Finally, you can provide your own method to totally control how the request is made: - * - * ```js - * url: { - * resource: "/services/todo", - * getListData: "GET /services/todos", - * getData: function(param){ - * return new Promise(function(resolve, reject){ - * $.get("/services/todo", {identifier: param.id}).then(resolve, reject); - * }); - * } - * } - * ``` - */ - - /** * @property {function} can-connect/data/url/url.ajax ajax * @parent can-connect/data/url/url.option diff --git a/data/url/url.url.md b/data/url/url.url.md new file mode 100644 index 00000000..1c5b4009 --- /dev/null +++ b/data/url/url.url.md @@ -0,0 +1,53 @@ +@property {String|Object} can-connect/data/url/url.url url +@parent can-connect/data/url/url.option + +Specify the url and methods that should be used for the "Data Methods". + +@option {String} If a string is provided, it's assumed to be a RESTful interface. For example, +if the following is provided: + +``` +url: "/services/todos" +``` + +... the following methods and requests are used: + + - `getListData` - `GET /services/todos` + - `getData` - `GET /services/todos/{id}` + - `createData` - `POST /services/todos` + - `updateData` - `PUT /services/todos/{id}` + - `destroyData` - `DELETE /services/todos/{id}` + +@option {Object} If an object is provided, it can customize each method and URL directly +like: + + @sourceref ./plain-endpoints.html + @highlight 23-29,only + @codepen + +You can provide a `resource` property that works like providing `url` as a string, but overwrite +other values like: + + @sourceref ./resource-param.html + @highlight 25,only + @codepen + +You can also customize per-method the parameters passed to the [can-connect/data/url/url.ajax ajax implementation], like: + @sourceref ./request-params.html + @highlight 30-36,only + @codepen +This can be particularly useful for passing a handler for the [can-ajax beforeSend] hook. + + +The [can-ajax beforeSend] hook can also be passed for all request methods. This can be useful when +attaching a session token header to a request: + + @sourceref ./beforeSend-all.html + @highlight 25-27,only + @codepen + +Finally, you can provide your own method to totally control how the request is made: + + @sourceref ./custom-request.html + @highlight 27-32,only + @codepen \ No newline at end of file