Skip to main content

Deprecating API Endpoints

Deprecating API endpoints without clear warnings can lead to broken integrations. APIMatic makes the deprecation process very simple by notifying developers when they use deprecated methods and educate them on the recommended alternatives.

Key Benefits

  • Deprecation Warnings: Deprecated endpoints trigger compiler warnings or runtime notices.
  • Detailed Deprecation Info: SDKs display the deprecation reason, affected version, and suggested alternatives.
  • Backward Compatibility: Deprecated endpoints remain functional to avoid breaking existing implementations while encouraging updates.

Mark endpoints deprecated in your OpenAPI Definition

The x-deprecation-details OpenAPI extension allows API authors to provide deprecation details such as the reason, the version in which a method was deprecated, and alternative options.

Below is an example demonstrating how to mark an endpoint as deprecated using this extension:

openapi: 3.0.3
info:
title: Product Management API
description: API for managing products in an inventory system.
version: 1.0.0
servers:
- url: https://api.example.com/v1
paths:
/products/legacy:
get:
summary: Retrieve all products (Deprecated)
description: |
**This endpoint is deprecated.**
Use the `/products` endpoint for enhanced filtering and pagination capabilities.
operationId: getAllProductsLegacy
deprecated: true
responses:
'200':
description: A list of products.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Product'
'410':
description: This endpoint is no longer available.
components:
schemas:
Product:
type: object
properties:
productName:
type: string
description: The name of the product.
quantity:
type: integer
description: Quantity of the product in stock.
required:
- productName

Usage in SDKs

Once the OpenAPI definition is updated, SDKs for supported languages will incorporate the deprecation details.

/**
* **This endpoint is deprecated.**
* Use the `/products` endpoint for enhanced filtering and pagination capabilities.
*
*
* @return Response from the API call
* @deprecated
*/
async getAllProductsLegacy(
requestOptions?: RequestOptions
): Promise<ApiResponse<Product[]>> {
...
}

Compiler or Runtime Warnings for Deprecated Endpoints

Here are examples of compiler or runtime warnings generated for the example in the respective languages. These warnings or messages typically appear during the build process or when the deprecated methods are invoked.

// TypeScript generates a warning when using deprecated methods like this:
let products = await api.getAllProductsLegacy();
// Warning: 'getAllProductsLegacy' is deprecated.
// Use the `/products` endpoint for enhanced filtering and pagination capabilities.
These warnings rely on language-specific tools or built-in annotation mechanisms to indicate deprecation during development or runtime.