Papupata Documentation

API Reference

class IncompleteAPIDeclaration

method body

Purpose

Declares body type for an API.

Usage

Path params and query parameters must be defined before query.

Parameters

NameTypeDescription
<BodyType>TypeThe body type is declared as a type parameter.
<BodyInputType>Type

The type of the body as seen when making a request. Defaults to BodyType.

This allows for setting up things like dates to be provided as date objects when there is an implicit conversion to strings when sending them as json. Using this parameter makes sense when there is a built-in conversion like with json, or if the function for making requests is meant to do other kind of transformation as well.

Returns

PartiallyDeclaredAPI

Caveats

  • There is no validation for the shape of the body on the server
  • This option is presented for methods without body, even if it is does nothing useful in those cases.

Examples

Declaration
import { APIDeclaration } from 'papupata'
const api = new APIDeclaration()
const myAPI = api.declarePostAPI('/do-stuff')
  .body<{value: number}>()
  .response<string>()
Usage in invocation
await myAPI({value: 123})
Usage in implementation
myAPI.implement(req => {
  const {value} = req.body
  return value.toString() // 123 in the example
})