API Reference
class APIDeclaration
method declarePostAPI
Purpose
Used for declaring an API using the HTTP POST methodUsage
APIs can be declared at any time.Parameters
Name | Type | Description |
---|---|---|
path | string | Path 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. |
routeOptions | varies | Options 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. |
papupataOptions | PapupataRouteOptions | Route-specific options papupata is aware of. |
Returns
PartiallyDeclaredAPIPapupataRouteOptions
Members
Name | Type | Data type/return type | Description |
---|---|---|---|
disableAutoImplement | property | boolean | Prevents 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. |
validationBehavior | property | ValidationBehavior | 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>()