dragonrend-response

Dragonrend Response Handler

Usage no npm install needed!

<script type="module">
  import dragonrendResponse from 'https://cdn.skypack.dev/dragonrend-response';
</script>

README

Build Status GitHub license

Dragonrend Response

Installation

$ npm install dragonrend-response

Example

const { Dragonrend } = require('dragonrend')
const response = require('dragonrend-response')

const app = new Dragonrend()

response(app, {
  defaultStatus: 201, // default is 200
  defaultContentType: 'text/plain', // default is application/json
  defaultBody: 'Created' // default is empty string
}) // second options argument is not required

// Server will return Response with status 201, contentType 'plain/text' and body 'Hello There'
app.get((ctx) => {
  ctx.response.status = 200
  ctx.response.contentType = 'application/json'
  ctx.response.body = { message: 'Hi There' }
})

app.toServer().listen(8080)

Author

Egor Repnikov - GitHub

License

This project is licensed under the MIT License - see the LICENSE file for details