Skip to content

Commit 13686be

Browse files
committed
feat(kitsu): post - add params parameter
BREAKING CHANGE
1 parent 85a192b commit 13686be

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

packages/kitsu/src/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ export default class Kitsu {
269269
* @memberof Kitsu
270270
* @param {string} model Model to create a resource under
271271
* @param {Object|Object[]} body Data to send in the request
272-
* @param {Object} [headers] Additional headers to send with the request
272+
* @param {Object} [config] Additional configuration
273+
* @param {Object} [config.params] JSON:API request queries. See [#get](#get) for documentation
274+
* @param {Object} [config.headers] Additional headers to send with the request
273275
* @returns {Object|Object[]} JSON-parsed response
274276
* @example <caption>Create a post on a user's profile feed</caption>
275277
* api.create('posts', {
@@ -289,8 +291,10 @@ export default class Kitsu {
289291
* { content: 'Another post' }
290292
* ])
291293
*/
292-
async post (model, body, headers = {}) {
294+
async post (model, body, config = {}) {
293295
try {
296+
const headers = merge(this.headers, config.headers)
297+
const params = merge({}, config.params)
294298
const [ resourceModel, url ] = splitModel(model, {
295299
resourceCase: this.resCase,
296300
pluralModel: this.plural
@@ -301,7 +305,11 @@ export default class Kitsu {
301305
camelCaseTypes: this.camel,
302306
pluralTypes: this.plural
303307
}),
304-
{ headers: Object.assign(this.headers, headers) }
308+
{
309+
headers,
310+
params,
311+
paramsSerializer: /* istanbul ignore next */ p => query(p)
312+
}
305313
)
306314

307315
return deserialise(data)

packages/kitsu/src/post.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('kitsu', () => {
2222
})
2323
return [ 200 ]
2424
})
25-
api.post('anime', { id: '1', type: 'anime' }, { extra: true }).catch(err => {
25+
api.post('anime', { id: '1', type: 'anime' }, { headers: { extra: true } }).catch(err => {
2626
done.fail(err)
2727
})
2828
done()

0 commit comments

Comments
 (0)