How to use kitsu-core - 10 common examples

To help you get started, we’ve selected a few kitsu-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wopian / kitsu / packages / kitsu / src / index.js View on Github external
const [ res, id, relationship ] = model.split('/')

      let url = this.plural(this.resCase(res))
      if (id) url += `/${id}`
      if (relationship) url += `/${this.resCase(relationship)}`

      /* istanbul ignore next */
      const { data } = await this.axios.get(url, {
        params,
        paramsSerializer: p => query(p),
        headers: Object.assign(this.headers, headers)
      })

      return deserialise(data)
    } catch (E) {
      throw error(E)
    }
  }
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
async get (model, params = {}, headers = {}) {
    try {
      const [ res, id, relationship ] = model.split('/')

      let url = this.plural(this.resCase(res))
      if (id) url += `/${id}`
      if (relationship) url += `/${this.resCase(relationship)}`

      /* istanbul ignore next */
      const { data } = await this.axios.get(url, {
        params,
        paramsSerializer: p => query(p),
        headers: Object.assign(this.headers, headers)
      })

      return deserialise(data)
    } catch (E) {
      throw error(E)
    }
  }
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
async self (params = {}, headers = {}) {
    try {
      const res = await this.get('users', Object.assign({ filter: { self: true } }, params), headers)
      return res.data[0]
    } catch (E) {
      throw error(E)
    }
  }
}
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
async delete (model, id, headers = {}) {
    try {
      const url = this.plural(this.resCase(model)) + '/' + id
      const { data } = await this.axios.delete(url, {
        data: serialise.apply(this, [ model, { id }, 'DELETE' ]),
        headers: Object.assign(this.headers, headers)
      })

      return data
    } catch (E) {
      throw error(E)
    }
  }
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
async patch (model, body, headers = {}) {
    try {
      const serialData = serialise.apply(this, [ model, body, 'PATCH' ])
      const url = this.plural(this.resCase(model)) + '/' + body.id
      const { data } = await this.axios.patch(
        url,
        serialData,
        { headers: Object.assign(this.headers, headers) }
      )

      return data
    } catch (E) {
      throw error(E)
    }
  }
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
async post (model, body, headers = {}) {
    try {
      const url = this.plural(this.resCase(model))
      const { data } = await this.axios.post(
        url,
        serialise.apply(this, [ model, body ]),
        { headers: Object.assign(this.headers, headers) }
      )

      return data
    } catch (E) {
      throw error(E)
    }
  }
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
async patch (model, body, headers = {}) {
    try {
      const serialData = serialise.apply(this, [ model, body, 'PATCH' ])
      const url = this.plural(this.resCase(model)) + '/' + body.id
      const { data } = await this.axios.patch(
        url,
        serialData,
        { headers: Object.assign(this.headers, headers) }
      )

      return data
    } catch (E) {
      throw error(E)
    }
  }
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
async delete (model, id, headers = {}) {
    try {
      const url = this.plural(this.resCase(model)) + '/' + id
      const { data } = await this.axios.delete(url, {
        data: serialise.apply(this, [ model, { id }, 'DELETE' ]),
        headers: Object.assign(this.headers, headers)
      })

      return data
    } catch (E) {
      throw error(E)
    }
  }
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
async post (model, body, headers = {}) {
    try {
      const url = this.plural(this.resCase(model))
      const { data } = await this.axios.post(
        url,
        serialise.apply(this, [ model, body ]),
        { headers: Object.assign(this.headers, headers) }
      )

      return data
    } catch (E) {
      throw error(E)
    }
  }
github wopian / kitsu / packages / kitsu / src / index.js View on Github external
        paramsSerializer: p => query(p),
        headers: Object.assign(this.headers, headers)

kitsu-core

Simple, lightweight & framework agnostic JSON:API (de)serialsation components

MIT
Latest version published 9 months ago

Package Health Score

74 / 100
Full package analysis