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
Name | Type | Data type/return type | Description |
---|---|---|---|
params | method | PartiallyDeclaredAPI | Declare URL/path parameters for the API. |
query | method | PartiallyDeclaredAPI | Declare URL/path required string query parameters for the API. |
optionalQuery | method | PartiallyDeclaredAPI | Declare URL/path optional query parameters for the API. |
queryBool | method | PartiallyDeclaredAPI | Declare URL/path optional query parameters for the API. Deprecated since 2.0.0. |
body | method | PartiallyDeclaredAPI | Declare body type. At this time the body must be an object. |
response | method | DeclaredAPI | Declare response type and conclude the declaration of an API. |
Examples
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>()