-
-
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
how to send raw request? #414
Comments
As in without JSON:API (de)serialisation - just regular JSON (etc.) requests? |
No it is a jsonapi request but with a custom URL |
There's nothing explicitly built-in to do that (middleware support would be a good feature request to make in a new issue). However the Axios instance is exposed so you can construct a custom PATCH request yourself using the methods from E.g: import Kitsu from 'kitsu'
import { serialise, deserialise } from 'kitsu-core'
const api = new Kitsu({ baseURL: 'https://example.com' })
const updatePassword = async (body) => {
const { data } = await api.axios.patch(
`users/${body.id}/password`, // Sends request to https://example.com/users/1/password
serialise('myModelType', body)
)
return deserialise(data)
}
updatePassword({ id: '1', password: 'myPassword' }) |
Although, deprecating the automatic extraction of Another weird choice I made years ago and yet another major breaking change if I go ahead with this in the future. |
Moved this to #415 to discuss this change further for a future api.patch(`users/${id}/password`, data) If #414 (comment) solves your issue in |
Thanks a lot for the quick answer. I think sending an object would simplify the call so I wonder if something like this would work? import Kitsu from 'kitsu'
import { serialise, deserialise } from 'kitsu-core'
const api = new Kitsu({ baseURL: 'https://example.com' })
api.rawRequest = async (payload) => {
const { data } = await api.axios.request({
method: payload.method,
url: payload.url,
data: serialise(payload.model, payload.body)
})
return deserialise(data)
} |
Added in e8aacc5 Documentation will be at https://github.com/wopian/kitsu/tree/master/packages/kitsu#request once it's released. Until then, example usage is available in the JSDoc comments here: https://github.com/wopian/kitsu/blob/master/packages/kitsu/src/index.js#L366-L423 E.g api.request({
method: 'PATCH',
url: 'anime',
type: 'anime',
body: { id: '1', subtype: 'tv' }
}) |
Released in |
@wopian I see the tests are passing but I still cannot call it from my app. I also do not see the declaration in the index.d.ts |
never mind it is working now v9.1.1 |
Sorry, I forgot to update the TypeScript definitions for the past few releases. From 9.1.2 onwards they're now updated during release (thanks to TS 3.7 supporting JSDoc) and I've improved the documentation to give TS users much better type information. |
Is there a way to send a raw request? for ex I used to do something like this with https://github.com/twg/devour:
The text was updated successfully, but these errors were encountered: