Papupata Documentation

API Reference

class IncompleteAPIDeclaration

method query

Purpose

Declares required string query parameters for an API

Usage

Only path params may be defined before query.

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

Parameters

NameTypeDescription
queryParamsTypeMappingNames 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', query2: 55})
// Invokes URL /do-stuff?query1=abc&query2=55
Usage in implementation
myAPI.implement(req => {
  const {query1, query2} = req.query
  return query1 + query2 // would return abc55 in the example, thought it should be noted that the 55 is actually a number, not a string
})