apic docs
  • About APIC
  • Installing APIC
  • Getting started with APIC
  • Designer
    • Getting Started With APIC designer
    • Working with API project
    • Creating a Folder
    • Creating a Model or Definitions
    • Creating a Trait
    • Creating an Endpoint
    • Write API Tests starting from Design Phase
    • API Security Definitions
    • Export and view Docs
  • Tester
    • Make an API call
    • Sending Forbidden request headers with APIC
    • Viewing API Response
    • Managing Environments
    • Using Environments
    • Using the Test Builder
    • Writing Test Cases
    • Response Schema validation
    • Creating Test Suites
    • Test Websocket
  • Test Real User Sessions
  • APIC Command line interface (apic-cli)
  • APIC Web Agent (apic-cli)
  • APIC CI/CD Integration (with Jenkins)
  • API Documentation
  • Simulator
  • Dashboard
    • Team Management
    • Published Docs
  • Sharing
Powered by GitBook
On this page
  • Example
  • What's next?

Was this helpful?

  1. Designer

Creating a Trait

PreviousCreating a Model or DefinitionsNextCreating an Endpoint

Last updated 5 years ago

Was this helpful?

Traits are nothing but reusable responses and parameters as specified by Swagger.

Traits will help you to define generic request and response patterns like query parameters, headers, response types (200, 404) etc and their respective response schema. You can reuse them with endpoints.

You can create a Trait by clicking on the Traits option in your Project Home page which will open a view as shown below to fill in the details and create your Trait. You can specify headers, query params, multiple response codes and their respective response schema as shown below.

Example

For example let's consider that all your API expect the user to send an authorization header and if the header is not present the API should return status code 401 with a field "error"(="Missing auth header.") in the response. Instead of adding the header and the 401 status code to each endpoint that you create, you can create a Trait and add that trait to each endpoint. Adding a Trait to an Endpoint will auto import everything from the trait.

Let's create a generic response pattern/trait for all error codes that our API may return like 404 (not found),401 (bad request) with the schema shown above and we will put it under Traits folder.

What's next?

Next we will for creating a ToDo.

create our API endpoint