-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document links pagination to retrieve the next/previous/first/last page #451
Comments
Kitsu.io uses Parameters (e.g. What is the:
|
@bagley2014 what is the request you're making with the package? |
Sorry, I should have taken the effort to provide a minimal reproducible example instead of just assuming it would be easy to reproduce. I went to work on one, and the issue might be that my include is in the query string, not a parameter to the function. (I'm doing it like that because I'm pulling the url from the relationship section of a response.) The code below should reproduce the error.
My output from this code is:
I'm using kitsu version 9.1.13, for the record. |
Thank you and no worries 👍
JSON:API request queries are not valid in the What you're after is the following: const address = 'users/103224/library-entries'
const params = { include: 'anime.animeStaff' }
api.get(address, params) // users/103224/library-entries?include=anime.animeStaff I'll update the documentation for the
|
Though not supported, so far I've been able to get the functionality I need by initializing the api with The reason I ended up with query parameters is that I thought the best solution for handling pagination would just be to make another api call using the "next" link that was returned. I think an example of getting all the pages of a library or something would be a valuable addition to the documentation as well. |
Parsing a JSON:API query is a little more complicated than the reverse (turning an object into a JSON:API query string) due to JSON:API having nested query parameters (i.e I'm reluctant to adding it to Which is something I'm trying to undo and avoid in the future with the existing
You can achieve this with Live demo: https://codesandbox.io/s/polished-sun-vsn7s?file=/src/index.js import { parse } from 'qs'
import Kitsu from 'kitsu'
const baseURL = 'https://kitsu.io/api/edge/'
const api = new Kitsu({ baseURL })
const next = 'https://kitsu.io/api/edge/users/103224/library-entries?include=anime.animeStaff&fields[anime]=slug&fields[library-entries]=progress,anime'
// [ 'users/library-entries', 'include=anime.animeStaff&fields[anime]=slug...' ]
const [address, params] = next.split(baseURL)[1].split('?')
// 'users/library-entries', { include: 'anime.animeStaff', fields: { anime: 'slug', ... } }
console.log(address, parse(params))
api.get(address, parse(params)) I'll add import { parse } from 'qs'
import Kitsu from 'kitsu'
const api = new Kitsu()
const next = 'https://kitsu.io/api/edge/users/103224/library-entries?include=anime.animeStaff&fields[anime]=slug&fields[library-entries]=progress,anime';
const [address, params] = next.split(api.baseURL)[1].split('?')
api.get(address, parse(params)) |
The
resourceCase
option defaults to 'kebab' even though that's invalid for Kitsu. For example, when trying to include "animeStaff" when fetching anime, the error "anime-staff is not a valid relationship of anime" is produced when using the default resource option.The text was updated successfully, but these errors were encountered: