Papupata Documentation

API Reference

class IncompleteAPIDeclaration

method params

Purpose

Declares url/path parameters for an API

Usage

If used, params must be declared before anything else.

The corresponding parameters have to defined in the API path, with express you'd use :varName syntax for it. Optional path parameters are not supported at this time.

Older styles are still supported in later versions, just not preferred.

Parameters

NameTypeDescription
paramsTypeMappingNames and types of the path parameters, as an object. See the examples and the TypeMapping itself for more information.

Returns

PartiallyDeclaredAPI

Examples

Declaration
import { APIDeclaration } from 'papupata'
const api = new APIDeclaration()
const myAPI = api.declarePostAPI('/do-stuff/:param1/:param2')
  .params({param1: String, param2: Number})
Usage in invocation
await myAPI({param1: 'abc', param2: 100})
// Invokes URL /do-stuff/abc/100
Usage in implementation
myAPI.implement(req => {
  const {param1, param2} = req.params
  return param1 + param2 // would return abc100 in the example, with param2 actually being a number
})