# How to scaffold Mule flows from a published API spec in Anypoint Code Builder (ACB)

> Why would you want to scaffold Mule flows from an API specification? This way you will be able to get started on your Mule application with a base project that is created upon your specification, instead of starting the Mule project and Mule flows from scratch.

- **Author:** Alex Martinez
- **Published:** Dec 7, 2023
- **Category:** Tutorials
- **Tags:** MuleSoft, Anypoint Code Builder, Anypoint Exchange, Visual Studio Code
- **Source:** https://prostdev.com/post/scaffold-mule-flows-from-published-api-spec-acb

---
In this post, I am going to show you how to scaffold your flows in Anypoint Code Builder from a published API specification.

> [!DOCS]
> To do this same thing in Anypoint Studio, refer to [How to scaffold Mule flows from a published API spec in Anypoint Studio](https://www.prostdev.com/post/scaffold-mule-flows-from-published-api-specification)

Why would you want to scaffold Mule flows from an API specification? This way you will be able to get started on your Mule application with a base project that is created upon your specification, instead of starting the Mule project and Mule flows from scratch.

Once you scaffold the Mule project, you will have:

- Mule flows for each HTTP method in your specification
- Basic error handling for different HTTP status codes
- Initial Mule project with some Transform Message components where applicable

## Prerequisites

- **Anypoint Platform** - You should have an Anypoint Platform account. You can create a new free trial account [here](https://anypoint.mulesoft.com/login/signup).
- **API specification** - You should already have an API specification published in Anypoint Exchange.
- **Visual Studio Code** - To use Anypoint Code Builder, you must first install VS Code. You can download it [here](https://code.visualstudio.com/).
- **Anypoint Extension Pack** - To enable Anypoint Code Builder in your Visual Studio Code, you must install this extension. You can install it from [here](https://marketplace.visualstudio.com/items?itemName=salesforce.mule-dx-extension-pack).
- **GitHub Repo** - If you want to follow along with the code I generated, you can check it out [here](https://github.com/ProstDev/codetober23/tree/main/day2).

> [!DOCS]
> If this is your first time creating an API specification, refer to [How to use MuleSoft's visual API Designer to create a To-Do API specification using clicks, not code](https://www.prostdev.com/post/how-to-use-mulesoft-s-visual-api-designer-to-create-a-to-do-api-specification-using-clicks-not-code)

## Create a Mule project in ACB

Once you are inside Anypoint Code Builder, select the **Implement an API** quick action.

![Anypoint Code Builder Quick Actions panel with the Implement an API option highlighted](../../assets/blog/scaffold-mule-flows-from-published-api-spec-acb-2.png)

This will open a new menu or window, and it will ask you to sign in to Anypoint Platform to retrieve the API Specification from your account. Click **Allow** and follow the prompts to sign in.

Once you are signed in, you will be able to search an API Specification from Exchange to implement it. Simply search for your asset's name on the search bar and select it from the list by clicking on **Add Asset**.

![New project form with name todoapp and an Exchange search listing the My To-Do API with Add Asset](../../assets/blog/scaffold-mule-flows-from-published-api-spec-acb-3.png)

> [!NOTE]
> If you're having issues searching for your asset, you can use the **Show filters** toggle to search for more specific assets. For example, using your own organization or the asset's type.

After the API Specification has been selected, click on **Create Project**. Wait a few seconds for everything to finish processing and you'll have the finalized project after that.

## Navigate the generated project

Once the project has been created, you should be able to see the flows in the configuration file located under `src/main/mule`.

![Scaffolded todoapp.xml shown as a flow canvas alongside its generated Mule XML](../../assets/blog/scaffold-mule-flows-from-published-api-spec-acb-4.png)

You can click on the **Flow List** button from the top-left of the graphical view (or the flow canvas) to see a complete list of all the flows that have been implemented in the current XML file.

![Flow List panel listing the generated GET, POST, PUT, and DELETE flows for the to-do API](../../assets/blog/scaffold-mule-flows-from-published-api-spec-acb-5.png)

The Error Handling has been added automatically to the main flow as well. This contains the HTTP status codes for some basic errors like 400 Bad Request or 404 Not Found.

![Auto-generated error handling with On Error Propagate blocks each routing to a Transform Message](../../assets/blog/scaffold-mule-flows-from-published-api-spec-acb-6.png)

Notice how some of the flows already have a Transform Message component for you to see which DataWeave code is needed to retrieve some data like the URI Parameter(s). This, of course, is just in the case that your API Specification contains a URI Parameter.

![Transform Message in a GET flow with DataWeave setting a variable from attributes.uriParams.id](../../assets/blog/scaffold-mule-flows-from-published-api-spec-acb-7.png)

There will also be Transform Message components added for some cases where you have set up an example in the API Specification.

![Transform Message with DataWeave returning a sample JSON to-do payload built from the spec example](../../assets/blog/scaffold-mule-flows-from-published-api-spec-acb-8.png)

Pretty cool, right?

Keep posted for some more articles on scaffolding in Anypoint Studio or Anypoint Code Builder!

Remember to subscribe at the bottom of the page to receive email notifications as soon as new content is published. ✨

💬 Prost! 🍻

---

## FAQs

### Why would I scaffold Mule flows from an API specification instead of starting from scratch?

Scaffolding lets you get started on your Mule application with a base project that is created from your specification, instead of building the Mule project and Mule flows from scratch.

### What does the scaffolded Mule project include?

Once you scaffold the project you get Mule flows for each HTTP method in your specification, basic error handling for different HTTP status codes, and an initial Mule project with some Transform Message components where applicable.

### What do I need before I can scaffold flows in Anypoint Code Builder?

You need an Anypoint Platform account, an API specification already published in Anypoint Exchange, Visual Studio Code installed, and the Anypoint Extension Pack installed to enable Anypoint Code Builder in VS Code.

### How do I create the Mule project in Anypoint Code Builder?

Inside Anypoint Code Builder select the Implement an API quick action, click Allow and sign in to Anypoint Platform when prompted, search for your asset's name and select it with Add Asset, then click Create Project and wait a few seconds for processing to finish.

### Where do I find the generated flows after the project is created?

You can see the flows in the configuration file located under `src/main/mule`, and clicking the Flow List button at the top-left of the graphical view shows a complete list of all the flows implemented in the current XML file.

### Why do some generated flows already contain a Transform Message component?

Some flows include a Transform Message component to show which DataWeave code is needed to retrieve data such as URI Parameters, which happens when your API Specification contains a URI Parameter, and additional Transform Message components are added for cases where you set up an example in the API Specification.