Closed yann-yinn closed 7 years ago
Here is a working example params object, will make a PR to add this as an example in the README for JSON API
const options = {
page: { limit },
filter: {
isPromoted: {
path:'isPromoted',
value: 1
}
},
include: "image,image.thumbnail",
fields: {
recipes: "title,difficulty,image",
images: "name,thumbnail",
files: "filename"
},
sort: '-created'
}
Hello ! First, Thanks a lot for your great work on waterwheel !
I open an issue because i was a little bit confused by "params" object format from json api get method
Here are my "params" object :
Here is the resulting url : http://dev-contentacms.pantheonsite.io/api/recipes?_format=api_json&fields%5Bfiles%5D=filename&fields%5Bimages%5D=name&fields%5Bimages%5D=thumbnail&fields%5Brecipes%5D=difficulty&fields%5Brecipes%5D=image&fields%5Brecipes%5D=title&include=image&include=image.thumbnail&page%5Blimit%5D=4&sort=-created
In a more readable way :
I expected it to works but :
Expected output for the object i passed should be, according to JSON API format :
include=image,image.thumbnail
And for the fields :
fields[images]=name,thumbnail
So i guess when using waterwheel with JSON API, I MUST always pass params object this way (using strings and not arrays for fields and include) ? Am i correct ? Maybe we could add a full working example in the documentation to have an example ?
Or is it JSON API module on PHP side that is supposed to understand correctly arrays of the first request ?
And just in case as an information, i was using this small module to write params as full objects and arrays, because i find it easier to manipulate arrays for "fields" and "include" keys than "concatened strings separated by commas" when i create my query dynamically
https://www.npmjs.com/package/d8-jsonapi-querystring