Papupata Documentation
Ø

API Reference

interface IncompleteApiDeclaration

Purpose

Used for defining the parameters and response types of an API.

Usage

Technically there is nothing called "IncompleteApiDeclaration" in the code base. This is simply a representation of what is returned when declaring the API.

There is, out of necessity, a somewhat odd restriction. Although you can skip any parts you do not need, the method calls have to take place in a specific order. This is necessary to avoid a combinatorial expolosion of types as the API is being declared. Luckily Typescript is perfectly aware of which methods are available and when. In brief, the order of declarations must be params, query, optional query, bool query, body and finally response.

The API declaration is done by invoking the methods exposed here in chain-like fashion. Once response is declared, you have a fully declared API which can then be implemented or called.

Members

NameTypeData type/return typeDescription
paramsmethodPartiallyDeclaredAPIDeclare URL/path parameters for the API.
querymethodPartiallyDeclaredAPIDeclare URL/path required string query parameters for the API.
optionalQuerymethodPartiallyDeclaredAPIDeclare URL/path optional query parameters for the API.
queryBoolmethodPartiallyDeclaredAPIDeclare URL/path optional query parameters for the API. Deprecated since 2.0.0.
bodymethodPartiallyDeclaredAPIDeclare body type. At this time the body must be an object.
responsemethodDeclaredAPIDeclare response type and conclude the declaration of an API.

Examples

Older styles are still supported in later versions, just not preferred.
import { APIDeclaration } from 'papupata'
const api = new APIDeclaration()
const myAPI = api.declarePostAPI('/do-stuff/:pathParam')
  .params({pathParam: String})
  .query({queryParam: String})
  .optionalQuery({opt: String})
  .body<{name: string}>()
  .response<string>()