---
schema_version: "1"
id: cbced021fb98ab61ab0ef26c91dd8a7e70af9ca844de87ad72b01b760fb181e9
title: APIkit for REST Scaffolding Reference
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/apikit/latest/apikit-4-scaffolding-reference.md
canonical_url: https://docs.mulesoft.com/apikit/latest/apikit-4-scaffolding-reference
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 8e639db487f47b399e58513cce80fcc256d270059a04247e4763d6470515620c
description: MuleSoft Documentation Site
release: 4.x
latest: true
---
---
product: APIkit
version: 4.x
is-latest-version: true
---

# APIkit for REST Scaffolding Reference

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

APIkit for REST scaffolders generate Mule flows and supporting components from RESTful API Modeling
Language (RAML) or OpenAPI Specification (OAS) contracts. Use Anypoint Studio to import an API from
Anypoint Exchange, Design Center, or local files and produce the implementation backbone
automatically. Scaffolding wires the HTTP listener, APIkit Router, API console flow, and per-action
flows you replace with business logic.

## API Scaffolding

Studio offers several ways to scaffold an API:

- From **New Mule Project wizard**, select **Scaffold Flows From These API Specifications** when
  importing a published API from Exchange or Maven, importing from a local file, or downloading from
  Design Center.

- From **Package Explorer**, right-click the API file and select **Mule** > **Generate flows from
  Local REST API**.

- From **Package Explorer**, right-click the API dependency and select **Generate flows** from its
  context menu.

> [!NOTE] Scaffolding from a local file is not supported for OAS. Scaffolding OAS APIs is available
> only for published assets in Exchange.

> [!NOTE] Anypoint Studio does not support OAS 3.1. Design OAS 3.1 specifications in
> [Anypoint Code Builder](https://docs.mulesoft.com/anypoint-code-builder/).

## Implementation Reference

When scaffolding a REST API specification, APIkit generates the following components:

- A main flow that acts as the entry point and includes:

  - HTTP Listener as a source

  - APIkit Router as the main operation

    APIkit Router is a message processor that directs messages from incoming API requests to the
    corresponding Mule flows and generates a serialized response using default values. For example,
    in an invalid request, APIkit generates a `bad request` response, and a missing associated flow
    for the requested API resource results in a `not implemented` response.

    While APIkit Router validates aspects such as request payload, headers, query parameters, and
    URI parameters, it does not validate all elements specified in an API specification.
    Specifically, the router does not perform security-related validation, such as authentication
    enforcement. Instead, the API gateway policies are responsible for this validation, which occurs
    before the request reaches the router.

  - Error Handler

- A secondary flow that exposes the API console and includes:

  - HTTP Listener as a source

  - APIkit Console as the main operation

  - Error Handler

- In addition to N flows, one per API action-resource-content-type combination, each flow includes:

  - No source (this option is available for APIkit for REST and SOAP applications only)

  - A mock implementation you substitute later with your actual business logic

## Supported MIME Types

APIkit for REST supports the following MIME types:

- JSON (application/json)

- XML (application/xml)

- Multipart Form Data (multipart/form-data)

- URL Encoded Form Data (application/x-www-form-urlencoded)

## Example

```xml
<mule>
    <apikit:config name="api-config" api="api.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
    <flow name="api-main">
        <http:listener config-ref="HTTP_Listener_config" path="/api/*">
            <http:response statusCode="#[vars.httpStatus default 200]">
                <http:headers>#[vars.outboundHeaders default {}]</http:headers>
            </http:response>
            <http:error-response statusCode="#[vars.httpStatus default 500]">
                <http:body>#[payload]</http:body>
                <http:headers>#[vars.outboundHeaders default {}]</http:headers>
            </http:error-response>
        </http:listener>
        <apikit:router config-ref="api-config" />
        <error-handler>
            <on-error-propagate type="APIKIT:BAD_REQUEST">
                <ee:transform>
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Bad request"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">400</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
            <on-error-propagate type="APIKIT:NOT_FOUND">
                <ee:transform>
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">404</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
            <on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
                <ee:transform>
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Method not allowed"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">405</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
            <on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
                <ee:transform>
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not acceptable"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">406</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
            <on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
                <ee:transform>
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Unsupported media type"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">415</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
            <on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
                <ee:transform>
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Not Implemented"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">501</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
        </error-handler>
    </flow>
    <flow name="api-console">
        <http:listener config-ref="HTTP_Listener_config" path="/console/*">
            <http:response statusCode="#[vars.httpStatus default 200]">
                <http:headers>#[vars.outboundHeaders default {}]</http:headers>
            </http:response>
            <http:error-response statusCode="#[vars.httpStatus default 500]">
                <http:body>#[payload]</http:body>
                <http:headers>#[vars.outboundHeaders default {}]</http:headers>
            </http:error-response>
        </http:listener>
        <apikit:console config-ref="api-config" />
        <error-handler>
            <on-error-propagate type="APIKIT:NOT_FOUND">
                <ee:transform>
                    <ee:message>
                        <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
{message: "Resource not found"}]]></ee:set-payload>
                    </ee:message>
                    <ee:variables>
                        <ee:set-variable variableName="httpStatus">404</ee:set-variable>
                    </ee:variables>
                </ee:transform>
            </on-error-propagate>
        </error-handler>
    </flow>
    <flow name="get:\users\userbyid:api-config">
        <ee:transform>
            <ee:message>
                <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
[
  {
    id: 3,
    name: "Clementine Bauch",
    username: "Samantha",
    email: "Nathan@yesenia.net",
    address: {
      street: "Douglas Extension",
      suite: "Suite 847",
      city: "McKenziehaven",
      zipcode: "59590-4157",
      geo: {
        lat: "-68.6102",
        lng: "-47.0653"
      }
    },
    phone: "1-463-123-4447",
    website: "ramiro.info",
    company: {
      name: "Romaguera-Jacobson",
      catchPhrase: "Face to face bifurcated interface",
      bs: "e-enable strategic applications"
    }
  }
]]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
    <flow name="get:\users:api-config">
        <ee:transform>
            <ee:message>
                <ee:set-payload><![CDATA[%dw 2.0
output application/json
---
[
  {
    id: 1,
    name: "Leanne Graham",
    username: "Bret",
    email: "Sincere@april.biz",
    address: {
      street: "Kulas Light",
      suite: "Apt. 556",
      city: "Gwenborough",
      zipcode: "92998-3874",
      geo: {
        lat: "-37.3159",
        lng: "81.1496"
      }
    },
    phone: "1-770-736-8031 x56442",
    website: "hildegard.org",
    company: {
      name: "Romaguera-Crona",
      catchPhrase: "Multi-layered client-server neural-net",
      bs: "harness real-time e-markets"
    }
  }
]]]></ee:set-payload>
            </ee:message>
        </ee:transform>
    </flow>
</mule>
```

## See Also

- [Error Handling Reference](https://docs.mulesoft.com/apikit/latest/apikit-error-handling-reference)
