Papupata Documentation

API Reference

class APIDeclaration

method declarePostAPI

Purpose

Used for declaring an API using the HTTP POST method

Usage

APIs can be declared at any time.

Parameters

NameTypeDescription
pathstringPath to the API under the base URL of the APIDeclaration.

Version 1.8.0 onwards: If you wish to declare different APIs on the same path but different query parameters, see Query-based variants for more information.

routeOptionsvariesOptions to the route. Type type is specified by the RouteOptions type parameter of the API declaration. They have no inherent meaning in papupata, they are simply stored to be used by the application.
papupataOptionsPapupataRouteOptionsRoute-specific options papupata is aware of.

Returns

PartiallyDeclaredAPI
PapupataRouteOptions

Members

NameTypeData type/return typeDescription
disableAutoImplementpropertybooleanPrevents automatic implementation of this route (as producing 501) even when the configuration option autoImplementAllAPIs is set to true (which is its default value in papupata 2.x). This is can be useful when there are a few routes that must be implemented in other ways for whatever reason.
validationBehaviorpropertyValidationBehavior

Can be used to override the validation behavior configured to be the default for all APIs. Papupata's own default is to throw upon validation failure, though an API declaration can be configured with a different default as well. A route-specific behavior can be used with this field.

The valid values are ValidationBehavior.THROW (which is the default descibed above) and ValidationBehavior.REROUTE which simply ignores the route if the parameters are not valid.

ValidationBehavior can be imported from papupata/config

Examples

import {APIDeclaration} from 'papupata'
const api = new APIDeclaration()

const MyAPI = api.declarePostAPI('/api/person')
  .response<string>()