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
Name | Type | Data type/return type | Description |
---|---|---|---|
() | method | Promise<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. |
getURL | method | string | Returns URL to the API. |
implement | method | void | Implement an API. |
implementWithMiddleware | method | void | Implement an API, providing additional middleware for it. |
implementation | property | Function | The current implementation for the API |
implementationMiddleware | property | object | Middleware for the current implementation |
method | property | string | The method of the api |
apiDeclaration | property | APIDeclaration | The API declaration on which this API was declared. |
implementation | property | Function | The current implementation for the API |
apiUrlParameters | property | object | Exposes the path and query parameters of the API. |
path | property | string | The path of the API, with path parameters left as placeholders. If you want a full URL, use the getURL method. |
ResponseType | property | n/a | The type of the response.. Type type itself must be accessed using the typeof operator. |
ServerResponseType | property | n/a | The type of the response as the server returns it.. Type type itself must be accessed using the typeof operator. |
CallArgsType | property | n/a | The type of the parameter object passed to invoke the API.. Type type itself must be accessed using the typeof operator. |
RequestType | property | n/a | The 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