Tech

How to design an API in Anypoint Code Builder

Photo of Olga Kepa, MuleSoft Developer Written by Olga Kepa, MuleSoft Developer,   Jun 7, 2023

In the first part of the blog, I described the basics of Anypoint Code Builder. Today, I will guide you through the design phase of the ‘Hello World’ project.

So, let’s start where we left off - at the Welcome Page.

Welcome page

Design

Let’s click on Design an API at the top of the Welcome Page.

Next, we select the project name, its location, API specification language and business group.

Design an API

Then, let’s click on Create Project.

To build specifications for our API, we follow the same steps as we would do to create a specification in Design Centre. In short, our specifications consist of the following:

  • Resource name – hello-world,
  • HTTP method – GET,
  • 200 status code,
  • Then in the response body, we will select content-type – application JSON,
  • We will include the hello-world.raml datatype stored in the folder datatypes,
  • We will also provide an example response.

Our raml specification is ready and looking like this:

raml specification

We’re good to test our raml specification using Mocking Service provided by Anypoint Code Builder.

In the top right corner, there’s an API console icon.

Mocking Service

After we click the API console button, we can see it looks the same as the mocking service we have in the Design Centre.

API console

Let’s click GET, under /hello-world endpoint.

documentation - GET

And now, we can click Try it. After sending the request, here is our response:

GET response

Our specification has been tested, so we can synchronise the changes with Design Centre.

On the left-hand side, there’s a Branch Icon; let’s click it. We can see the two files we've added (one inside a datatypes folder). Let’s stage the files and type the commit message “initial commit”, and commit our changes.

view and commit previously created files

Now, we will click on synchronise button and confirm, pushing the changes to the origin/master.

synchronise changes

push changes and commit

Then, we will be prompted to open Anypoint Platform.

open Anypoint Platform

After clicking Allow, ACB will push the commit. After this is done, in the Design Centre, we can see our specifications.

Design Centre

We are good to publish the specification to Exchange now. To do this, we click Ctrl+Shift+P. Next, from the list, we select the command: MuleSoft: Publish API specification to Exchange.

publish the specification to Exchange

We are now prompted to select: the project name, artefact id, asset version and API version. After this, the asset will be published to Exchange, and we can see it there:

asset is published to Exchange

And that’s it! Now our specification has been published. Overall the process was similar to designing the specification in Design Centre and Publishing it to Exchange.

In the next part of this blog, we will focus on implementing and deploying the API using Anypoint Code Builder.

We’d love to hear your opinion on this post