此内容没有您所选择的语言版本。

Chapter 2. Design and develop an API definition with Apicurito


You can use Apicurito to design and develop a REST API definition that complies with the OpenAPI 2.0 specification.

Prerequisites

  • You created an OpenShift project.
  • You added the Apicurito service to your OpenShift project.

2.1. Creating a REST API definition

The following steps describe how to create an example REST API definition for managing address data (including information such as street, city, state, zipcode, and so on). To implement the address example, you create two paths - one for addresses and one for a specific address. You then define operations to get a list of all addresses, add an address, update an address, get the details of an address, and delete an address.

Note

Apicurito is stateless, meaning that it does not save your work between OpenShift sessions. You need to save the API to your local file system between sessions.

Prerequisites

  • You created an OpenShift project.
  • You added the Apicurito service to your OpenShift project.
  • You know the endpoints for the API that you want to create. For the Address example, there are two endpoints: addresses and addresses{addressId}.

Procedure

  1. Log in to your OpenShift web console and then open the project that contains Apicurito.
  2. In the list of applications, click the URL for Apicurito, for example https://apicurito-myproject.192.168.64.43.nip.io

    A new browser window or tab opens for Apicurito:

    Note

    Because Apicurito is a “light” version of the Apicurio Studio open source project, "Apicurio" shows in the Apicurito interface.

  3. Click New API.

    A new API page opens.

    By default, the API name is New API, the version is 1.0, and the input and output types are application/json.

  4. To change the API name:

    1. Hover the cursor over the name and then click the edit icon ( apicurito pencil ) that appears.
    2. Edit the name. For example, type AddressBook API.
    3. Click Save.
  5. Optionally:

    • Add your contact information (name, email address, and URL).
    • Select a license.
    • Define tags.
    • Select a security scheme.
    • Specify security requirements.
  6. Define a relative path to each individual endpoint of the API. The field name must begin with a slash (/).

    For the AddressBook API example, create two paths:

    • A path for addresses: /addresses
    • A path for a specific address by ID: /addresses/{addressId}

  7. Specify the type of any path parameters.

    For the addressID parameter example:

    1. In the Paths list, click /addresses/{addressId}.

      The addressId parameter appears in the PATH PARAMETERS section.

    2. Click Create, and then click Edit.
    3. For the type, select string.
    4. Accept string for the format, and then click OK.
  8. In the Data Types section, define reusable types for the API.

    1. Click Add a data type.
    2. In the Add Data Type dialog, type a name, for example Address.
    3. Optionally, you can provide an example from which Apicurito creates the data type’s schema. You can then edit the generated schema.

      For the AddressBook API example, start with the following JSON example:

      {
      "Id" : "12345",
      "City" : "Boston",
      "State" : "MA"
      }
      Copy to Clipboard Toggle word wrap
    4. Optionally, you can choose to create a REST Resource with the data type.
    5. Click Save. If you provided an example, Apicurito generates a schema from the example:

      You can add edit the properties and add new ones, for example street, zipcode, and country.

  9. For each path, define operations (GET, PUT, POST, DELETE, OPTIONS, HEAD, and PATCH).

    For the AddressBook API example, define the following operations:

    • /addresses path:

      • GET - Lists all addresses.
      • POST - Adds an address.
    • /addresses/{addressId} path:

      • GET - Gets an address.
      • PUT - Updates an address.
      • DELETE - Deletes an address.
  10. For each operation define a response.

    For the AddressBook API example:

    • To define a response for the /addresses GET operation:

      1. Click the green GET button.
      2. Click Add a response.
      3. For Response Status Code, select 200 and then click Add.
    • To define a response for the /addresses POST operation:

      1. Click the POST button.
      2. For Request Body Type, select Address.
      3. For Response, click Add a response.
      4. For Response Status Code, select 201 Created and then click Add.
  11. For each response, provide a description.

    For example:

  12. Resolve any issues, as described in Section 2.2, “Resolving issues in Apicurito”.
  13. Click Save As Save as JSON.

    The JSON file is downloaded to your local download folder. The default filename is openapi-spec.

Additional resources

2.2. Resolving issues in Apicurito

When you create and edit an API, Apicurito identifies issues that you must resolve with an exclamation (!) icon.

Prerequisites

  • Open an API in Apicurito.

Procedure

  1. Find an issue indicated by an exclamation (!) icon. For example:

  2. Click the exclamation icon to view a description of the issue. For example:

  3. Based on the information provided by the issue description, navigate to the location of the issue and fix it.

    For example, open the PUT operation and then add a description for the response.

    After you add a description, the issue is resolved and the exclamation icon disappears:

  4. For a summary of all issues:

    1. Click the Issues link in the upper right corner.

    2. Click Go to a problem for a specific issue to go to the location of the issue so that you can resolve it.

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat