Papupata Documentation

API Reference

interface DeclaredAPI

Purpose

Represents a declared API and allow interacting with it.

Usage

Technically there is nothing called "DeclaredAPI" in the code base. This is simply a representation of what is returned when an API has been declared.

Some of the types used for the API are exposed in an unusual fashion. In the future we might look into adding some wrapper types that allow for more conventional means for accessing them.

Members

NameTypeData type/return typeDescription
()methodPromise<ResponseType>DeclaredAPI itself is a function, which can be called to call the API itself. The response is returned wrapped in a promise. Error handling is dependant on the adapter being used.
getURLmethodstringReturns URL to the API.
implementmethodvoidImplement an API.
implementWithMiddlewaremethodvoidImplement an API, providing additional middleware for it.
implementationpropertyFunctionThe current implementation for the API
implementationMiddlewarepropertyobjectMiddleware for the current implementation
methodpropertystringThe method of the api
apiDeclarationpropertyAPIDeclarationThe API declaration on which this API was declared.
implementationpropertyFunctionThe current implementation for the API
apiUrlParameterspropertyobjectExposes the path and query parameters of the API.
pathpropertystringThe path of the API, with path parameters left as placeholders. If you want a full URL, use the getURL method.
ResponseTypepropertyn/aThe type of the response.. Type type itself must be accessed using the typeof operator.
ServerResponseTypepropertyn/aThe type of the response as the server returns it.. Type type itself must be accessed using the typeof operator.
CallArgsTypepropertyn/aThe type of the parameter object passed to invoke the API.. Type type itself must be accessed using the typeof operator.
RequestTypepropertyn/aThe type of the modified express request passed to the impementing function.. Type type itself must be accessed using the typeof operator.

Examples

Using the exposed types
import { APIDeclaration } from 'papupata'
const api = new APIDeclaration()
const myAPI = api.declarePostAPI('/do-stuff/:pathParam')
  .response<string>()

type RespType = typeof myAPI['ResponseType']
// RespType is now string