Overview
OpenAPI calls allow you to invoke operations defined in OpenAPI documents, automatically handling parameter binding, request formatting, and response parsing based on the specification.Properties
The OpenAPI document that defines the operation to call.Can reference OpenAPI 2.0 (Swagger), 3.0, or 3.1 specifications.
The id of the OpenAPI operation to call.Must match an operationId defined in the OpenAPI document.
A name/value mapping of the parameters, if any, of the OpenAPI operation to call.Parameter names must match those defined in the operation’s parameters section.
The authentication policy, or the name of the authentication policy, to use when calling the OpenAPI operation.
The OpenAPI call’s output format.Supported values:
raw- Outputs the base-64 encoded HTTP response content, if anycontent- Outputs the content of HTTP response, possibly deserializedresponse- Outputs the full HTTP response object
Specifies whether redirection status codes (300-399) should be treated as errors.
- If
false, runtimes must raise an error for response status codes outside the 200-299 range - If
true, they must raise an error for status codes outside the 200-399 range
External Resource
Thedocument property references an external resource:
The endpoint at which to get the OpenAPI document.
The name, if any, of the defined resource.
Examples
Basic OpenAPI Call
With Multiple Parameters
With Authentication
Using as Reusable Function
With Redirection Handling
Full Response Output
Parameter Mapping
OpenAPI operations can have parameters in different locations:- Path parameters: Embedded in the URL path (e.g.,
/pets/{petId}) - Query parameters: Appended to the URL (e.g.,
?status=available) - Header parameters: Sent as HTTP headers
- Cookie parameters: Sent as cookies
- Body parameters: Sent in the request body
Benefits
- Type Safety: Parameters and responses are validated against the OpenAPI schema
- Auto-Discovery: Operation details are extracted from the OpenAPI document
- Documentation: OpenAPI documents serve as living documentation
- Tooling: Leverage existing OpenAPI tooling and generators
Best Practices
- Cache OpenAPI Documents: Reference remote OpenAPI documents that are cached and versioned
- Use OperationIds: Ensure all operations in your OpenAPI spec have unique operationIds
- Version Your APIs: Include version information in the OpenAPI document endpoint URL
- Handle Errors: Use try/catch blocks to handle API errors gracefully
Related
- HTTP Protocol - For direct HTTP calls without OpenAPI
- AsyncAPI Protocol - For event-driven APIs
- Authentication - Authentication schemes for API calls