Papupata Documentation

API Reference

class IncompleteAPIDeclaration

method optionalQuery

Purpose

Declares optional string query parameters for an API

Usage

Only path params and required string query parameters may be defined before query.

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

Parameters

NameTypeDescription
optionalQueryParamsTypeMappingNames and types of the query 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')
  .query({ query1: String, query2: Number })
  .response<string>()
Usage in invocation
await myAPI({query1: 'abc})
// Invokes URL /do-stuff?query1=abc
Usage in implementation
myAPI.implement(req => {
  const {query1, query2} = req.query
  return query1 + query2 // would return abcundefined
})