Reading Time: 9 minutes

Anypoint Platform is a complete suite of products that cover full lifecycle API management. The first step in this lifecycle is the design of the API specification, and MuleSoft does this through Anypoint Design Center. In Anypoint Design Center, users can choose to design API specs using RAML/OAS by writing code or using a visual tool. 

What we present now concerns an open-source project on Anypoint Platform, where, with the introduction of AI, we can delegate the design of the API specification to the AI using the Design Center. 

Design Center 

In Design Center, there are two options for creating a complete API specification, either creating a specification using one of the two available languages (RAML or OAS) or using a visual tool. Consider the following: 

You can choose between: 

  • “I’m comfortable designing it on my own”: You can define the specifications of an API by choosing to do so using one of the two languages ​​provided by MuleSoft: RAML (REST API modeling language) or OAS (Open API Specification) in their respective versions.
  • “Guide me through it”: This is a simple way that uses a visual interface that scaffolds the API specification. It’s able to generate both RAML and OAS. 

In both cases, you will design the specification of an API in a very simple and intuitive way, accelerating the delivery of the project without any margin of error.

Design Center and AI 

With generative AI taking over many business operations, a popular method is incorporating large language models (LLMs) into business systems, with APIs offering a convenient way to access and interact with these models.

To demonstrate this in action, we’ll show you a new version of the Design Center that uses AI. In this version, AI is used to modify Design Center to ensure that there is a third option available for creating an API specification: use AI in order to let AI generate a complete OAS 3.0 JSON. 

This is the new scenario:

As you can see, the UI has changed. Now, there’s one more option you can choose on how to define the API specification:

  • Use AI: Let AI generate a complete definition 

By choosing this third option, we are asking and delegating to the AI ​​the creation of the AI ​​specification. Of course we must then give the AI ​​instructions to follow to do this.

Checking this option, we now have the possibility to use AI in two ways:

  • Project name: Specifying only the API name, we leave the AI full control of creating the API specification based on RAML or OAS (you can choose this). For example, you can insert customers, products, or orders: 
  • Prompt: By entering a prompt. In this way you can post a specific request to the AI, using a simple lineage and with the accuracy and detail you prefer. If we want AI to create a spec related to an ‘orders’ object, we can use this prompt: ‘Create a OAS 3.0 JSON, with methods get,post,update,delete for orders api that have these fields: id,name,email, phone’.

Once you’ve chosen the way to provide instructions to AI, by using its LLM, the AI prompt ​​will produce the specification of the requested API in the requested format. This will be the result:

This is the API specification generated by AI:

{

  "openapi": "3.0.0",

  "info": {

    "version": "1.0.0",

    "title": "Orders API"

  },

  "paths": {

    "/orders": {

      "get": {

        "summary": "Get all orders",

        "responses": {

          "200": {

            "description": "List of orders",

            "content": {

              "application/json": {

                "schema": {

                  "type": "array",

                  "items": {

                    "type": "object",

                    "properties": {

                      "id": {

                        "type": "integer"

                      },

                      "price": {

                        "type": "number"

                      },

                      "date": {

                        "type": "string",

                        "format": "date"

                      }

                    }

                  }

                }

              }

            }

          }

        }

      },

      "post": {

        "summary": "Create a new order",

        "requestBody": {

          "required": true,

          "content": {

            "application/json": {

              "schema": {

                "type": "object",

                "properties": {

                  "id": {

                    "type": "integer"

                  },

                  "description": {

                    "type": "string"

                  },

                  "price": {

                    "type": "number"

                  },

                  "date": {

                    "type": "string",

                    "format": "date"

                  }

                }

              }

            }

          }

        },

        "responses": {

          "201": {

            "description": "Order created successfully"

          }

        }

      }

    },

    "/orders/{id}": {

      "parameters": [

        {

          "in": "path",

          "name": "id",

          "required": true,

          "schema": {

            "type": "integer"

          }

        }

      ],

      "get": {

        "summary": "Get order by ID",

        "responses": {

          "200": {

            "description": "Order details",

            "content": {

              "application/json": {

                "schema": {

                  "type": "object",

                  "properties": {

                    "id": {

                      "type": "integer"

                    },

                    "price": {

                      "type": "number"

                    },

                    "date": {

                      "type": "string",

                      "format": "date"

                    }

                  }

                }

              }

            }

          }

        }

      },

      "put": {

        "summary": "Update order",

        "requestBody": {

          "required": true,

          "content": {

            "application/json": {

              "schema": {

                "type": "object",

                "properties": {

                  "price": {

                    "type": "number"

                  },

                  "date": {

                    "type": "string",

                    "format": "date"

                  }

                }

              }

            }

          }

        },

        "responses": {

          "200": {

            "description": "Order updated successfully"

          }

        }

      },

      "delete": {

        "summary": "Delete order",

        "responses": {

          "204": {

            "description": "Order deleted successfully"

          }

        }

      }

    }

  }

}

API management and AI go hand-in-hand for IT 

We’ve already learned how to use gen AI and MuleSoft to create AI custom policies, but now, we can use easy-to-understand instructions to delegate the definition of the specification of an API to AI, thus saving time and accelerating project delivery.