2.1.0 • Published 2 years ago

adonis-kvn-response v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Adonis v5 Kvn Response

This addon adds the functionality to integrate common REST API responses to Response class of HttpContext.

Installation

Make sure to install it using npm or yarn.

# npm
npm i adonis-kvn-response
node ace invoke adonis-kvn-response

# yarn
yarn add adonis-kvn-response
node ace invoke adonis-kvn-response

Usage

Make sure to register the provider inside .adonisrc.json file.

"providers": [
  "...other packages",
  "adonis-kvn-response"
]

For TypeScript projects add to tsconfig.json file:

"compilerOptions": {
  "types": [
    "...other packages",
    "adonis-kvn-response/build/adonis-typings"
  ]
}

Example

response.ok()

public async someFunction({ response, auth }: HttpContextContract) {
  return response.ok('Your messaged here.')
}

response.data()

public async someFunction({ response, auth }: HttpContextContract) {
  return response.data({
    email: email,
    name: name
  }, 'Your messaged here is optional')
}

response.resource()

Note: Need to install adonis-bumblebee-ts to be able to use this function for transforming data

public async listItems({ response, auth, transform }: HttpContextContract) {
  return response.resource(await transform.collection(items, ItemTransformer))
}

public async showItem({ response, auth, transform }: HttpContextContract) {
  return response.resource(await transform.item(item, ItemTransformer))
}

response.accepted()

Note: For creating record status code = 201

public async store({ response, auth, transform }: HttpContextContract) {
  return response.accepted({
    id: id,
    name: name
  })
}

response.error()

response.unableToProcess()

response.notFound()

response.forbidden()

response.unauthorized()

response.badRequest()

2.0.3

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.1.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago