can-connect/data/parse/parse
Extract response data into a format needed for other extensions.
dataParse( baseConnection )
Overwrites the DataInterface methods to run their results through either parseInstanceData or parseListData.
Parameters
- baseConnection
{Object}
:The base connection.
Use
data/parse
is used to modify the response data of "data interface" methods to comply with what
is expected by "instance interface" methods. For example, if a service was returning list data
at the /services/todos
url like:
{
todos: [
{todo: {id: 0, name: "dishes"}},
{todo: {id: 2, name: "lawn"}}
]
}
That service does not return ListData in the right format which should look like:
{
data: [
{id: 0, name: "dishes"},
{id: 2, name: "lawn"}
]
}
To correct this, you can configure data-parse
to use the parseListProp and parseInstanceProp
as follows:
connect([
require("can-connect/data/parse/parse"),
require("can-connect/data/url/url")
],{
parseListProp: "todos",
parseInstanceProp: "todo"
})