API discovery
  • 27 Dec 2022
  • 3 Minutes to read
  • PDF

API discovery

  • PDF

Article Summary

API discovery rules consists of API exclusion and API naming rules. These rules help you in better managing the number of APIs being monitored or naming the APIs. When you create a rule, the rule applies to future requests. To create meaningful rules, you must have reasonable knowledge of regular expressions. You can use websites, like, regex101 to view and learn regular expressions. After you configure these rules, the API Catalog displays the APIs based on these rules.

Exclusion rule

If you have numerous APIs in your API infrastructure, and you want to monitor only a specific number of APIs, you can create an exclusion rule to exclude an API or a set of APIs. Navigate to Administration (image-1638268402925> API Catalog > API Discovery. Click on the Exclusions tab to create an exclusion rule. If you have more than one rule, they are applied in the order they are listed. For example, the following demo clip shows a rule to exclude any URI which has the term "frontend/register" in it. 

When you add the pattern "frontend/register" in the URL Regex Pattern text field and click on Show Preview, Traceable shows a preview of all the URIs that have the word match anywhere in the URI. Traceable does a partial match of the word, that is, it gives a match if the word appears anywhere in the URI. In the example above, the match is for URIs in the last six hours. You can change the time-period to 12-hours or 1-day to see all the matching URIs. If you are satisfied that all the required URIs are listed, you can Enable the rule and Save it. If you want better match results, provide a more fine-tuned regular expression. You can choose to apply this rule across all the environments and services, or you can choose a one or more than one environment and their corresponding services.

Naming rules

Naming rules are helpful in situations when you want to exclude certain portions from the Traceable provided API names. You can also create a naming rule to give an entirely different name to the discovered API. Similarly to exclusion  rule, you would need to have reasonable knowledge of regular expressions to match the exact URI patterns and create a new API name.  Navigate to Administration (image-1638268402925> API Discovery and click on Naming tab. Click on Create Naming Rule. Similar to exclusion rules, you can apply the naming rule to all environments or to one or more than environments and their specific services. 

For example, if the API named by Traceable is _order/health/traceable__cart__test__tags__123456__0 and you wish to rename it as order/health/tags then add the _order/health/.+__(.+)__.+__0 regular expression in Step 2: Request Matching to match such APIs. Click on Show Preview to view the matching URIs in the selected time range. To name such APIs as mentioned earlier, you can give the regular expression as order/health/$1 in Step 3: API Endpoint Naming. Click on Show Preview to view the API Endpoint naming result. If it matches your requirements, Enable the rule and Save it.

An important point to note is that the number of segments in the Request Matching section and API Endpoint Naming section should be the same. For example, as shown above, there are three segments in Request Matching (step 2) and API Endpoint Naming (Step 3).

ID examples

Following are a few examples for naming:

Single ID

For example, if you have URLs that are like:

  • orders/1Dvb0-xaLTnwYbkGxmMPq3cYdZFHkUSxIUWTGahW3aWM 
  • orders/1bw-G30aoMUa8XS7L6x-nAS0j4T6A_wWUCCxQqYB9xa

and you want to rename them as orders/{orders-id}, then the rule should be configured as:

Regex - orders/[a-zA-Z0-9-_]+

The renamed URL would be orders/{orders-id}

Multiple IDs

For example, if you have URLs that are like:

  • users/alice/orders/1bw-G30aoMUa8XS7L6x-nAS0j4T6A_wWUCCxQqYB9xag 
  • users/bob/orders/1bw-G30aoMUa8XS7L6x-nAS0j4T6A_wWUCCxQqYB9xag

and you wish to rename them as users/{users-id}/orders/{orders-id}, then the rule should be configured as:

Regex - users/[a-zA-Z]+/orders/[a-zA-Z0-9-_]+

The renamed URL would be users/{users-id}/orders/{orders-id}

Group examples

Simple Groups

If you have URLs with groups, for example, URLs like:

  • blogs/2014-flags-are-a-code-smell 
  • blogs/2012-boolean-as-primitive-argument

and you want to rename them as:

  • blogs/flags-are-a-code-smell 
  • blogs/boolean-as-primitive-argument 

then, configure the rule as:

Regex - blogs/[0-9]{4}-([a-z-]+), that is, ( and ) are used to capture the groups.

The renamed URL would be blogs/$1. In the renamed URL, $1 points to first captured group. Similarly, $2 would capture the second group and $3 would capture the third group and so on.

Rearrange groups

If you have URLs with groups, for example:

  • users/browse/products 
  • users/browse/catalog 
  • users/checkout/cart

In the renamed URL, you want to rearrange the groups as:

  • users/products/browse 
  • users/catalog/browse 
  • users/cart/checkout 

then, configure the rule as:

Regex - users/([a-z]+)/([a-z]+)

The renamed URLs would be of the form users/$2/$1

Was this article helpful?