json

Response method responsible for handling json style payloads

circle-info

The json method is a curried function so you don't need to send the parameters all at once

const { response } = require('octoris')

Arguments

Name

Type

Description

code

Number

The status code to set for the response

data

Any

The json payload to send back to the requester

circle-exclamation

Usage

circle-info

You would use the response functions within your method handlers you can read about the methods herearrow-up-right

const { response } = require('octoris')
// Since responses are curried we can create a basic status code constant
const OK = response.json(200)

function homeHandler (ctx) {
  return OK({ foo: 'bar' })
}

function aboutHandler (ctx) {
  return response.send(201, { a: 1, b: 2 })
}

Last updated

Was this helpful?