Skip to content

Commit 85937c4

Browse files
committed
refactor(kitsu): request - move headers into config object
BREAKING CHANGE
1 parent edb7e07 commit 85937c4

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

packages/kitsu/src/index.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { camel, deserialise, error, kebab, query, serialise, snake, splitModel } from 'kitsu-core'
12
import axios from 'axios'
23
import pluralise from 'pluralize'
34
import { camel, deserialise, error, kebab, query, serialise, snake, splitModel } from 'kitsu-core'
@@ -392,15 +393,8 @@ export default class Kitsu {
392393
* @param {string} config.type The resource type
393394
* @param {Object|Object[]} [config.body] Data to send in the request
394395
* @param {string} [config.method] Request method - `GET`, `PATCH`, `POST` or `DELETE` (defaults to `GET`, case-insensitive)
395-
* @param {Object} [config.params] JSON-API request queries. Any JSON:API query parameter not mentioned below is supported out of the box.
396-
* @param {Object} [config.params.page] [JSON:API Pagination](http://jsonapi.org/format/#fetching-pagination). All pagination strategies are supported, even if they are not listed below.
397-
* @param {number} [config.params.page.limit] Number of resources to return in request (Offset-based) - **Note:** For Kitsu.io, max is `20` except on `libraryEntries` which has a max of `500`
398-
* @param {number} [config.params.page.offset] Number of resources to offset the dataset by (Offset-based)
399-
* @param {number} [config.params.page.number] Page of resources to return in request (Page-based) - **Note:** Not supported on Kitsu.io
400-
* @param {number} [config.params.page.size] Number of resources to return in request (Page-based and cursor-based) - **Note:** Not supported on Kitsu.io
401-
* @param {string} [config.params.page.before] Get the previous page of resources (Cursor-based) - **Note:** Not Supported on Kitsu.io
402-
* @param {string} [config.params.page.after] Get the next page of resources (Cursor-based) - **Note:** Not Supported on Kitsu.io
403-
* @param {Object} [headers] Additional headers to send with the request
396+
* @param {Object} [config.params] JSON:API request queries. See [#get](#get) for documentation
397+
* @param {Object} [config.headers] Additional headers to send with the request
404398
* @returns {Object} JSON-parsed response
405399
* @example <caption>Raw GET request</caption>
406400
* api.request({
@@ -440,7 +434,7 @@ export default class Kitsu {
440434
* ]
441435
* })
442436
*/
443-
async request ({ body, method, params, type, url }, headers = {}) {
437+
async request ({ body, method, params, type, url, headers }) {
444438
try {
445439
method = method?.toUpperCase() || 'GET'
446440
const { data } = await this.axios.request({
@@ -450,10 +444,9 @@ export default class Kitsu {
450444
camelCaseTypes: this.camel,
451445
pluralTypes: this.plural
452446
}),
447+
headers: Object.assign(this.headers, headers),
453448
params,
454-
/* istanbul ignore next */
455-
paramsSerializer: p => query(p),
456-
headers: Object.assign(this.headers, headers)
449+
paramsSerializer: /* istanbul ignore next */ p => query(p)
457450
})
458451

459452
return deserialise(data)

packages/kitsu/src/request.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ describe('kitsu', () => {
4444
api.request({
4545
method: 'GET',
4646
url: 'users',
47-
model: 'users'
48-
}, { extra: true }).catch(err => {
47+
model: 'users',
48+
headers: { extra: true }
49+
}).catch(err => {
4950
done.fail(err)
5051
})
5152
done()

0 commit comments

Comments
 (0)