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 5a81a2ec..10fa2bd1 100644 --- a/data/url/url.js +++ b/data/url/url.js @@ -159,93 +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