|
2 | 2 |
|
3 | 3 | Use this skill when integrating with external REST APIs from Mendix. |
4 | 4 |
|
5 | | -## Two Approaches |
| 5 | +## Three Approaches |
6 | 6 |
|
7 | | -Mendix offers two ways to call REST APIs from microflows. Choose based on the use case: |
| 7 | +Mendix offers three ways to call REST APIs from microflows. Choose based on the use case: |
8 | 8 |
|
9 | 9 | | Approach | When to Use | Artifacts | |
10 | 10 | |----------|-------------|-----------| |
11 | | -| **REST Client + SEND REST REQUEST** | Structured APIs with multiple operations, reusable across microflows, Studio Pro UI support | REST client document + microflow | |
| 11 | +| **OpenAPI import** | API has an OpenAPI 3.0 spec — auto-generate from the spec | REST client document generated in one command | |
| 12 | +| **REST Client (manual)** | No spec available, or need fine-grained control | REST client document + microflow | |
12 | 13 | | **REST CALL (inline)** | One-off calls, quick prototyping, dynamic URLs, low-level HTTP control | Microflow only | |
13 | 14 |
|
14 | | -Both can be combined with **Data Transformers** (Mendix 11.9+) and **Import/Export Mappings** to map between JSON and entities. |
| 15 | +Both REST Client approaches can be combined with **Data Transformers** (Mendix 11.9+) and **Import/Export Mappings** to map between JSON and entities. |
15 | 16 |
|
16 | 17 | --- |
17 | 18 |
|
18 | | -## Approach 1: REST Client (Recommended) |
| 19 | +## Approach 0: OpenAPI Import (Fastest) |
| 20 | + |
| 21 | +If the API has an OpenAPI 3.0 spec (JSON or YAML), generate the REST client in one command: |
| 22 | + |
| 23 | +```sql |
| 24 | +-- From a local file (relative to the .mpr file) |
| 25 | +create or modify rest client CapitalModule.CapitalAPI ( |
| 26 | + OpenAPI: 'specs/capital.json' |
| 27 | +); |
| 28 | + |
| 29 | +-- From a URL |
| 30 | +create or modify rest client PetStoreModule.PetStoreAPI ( |
| 31 | + OpenAPI: 'https://petstore3.swagger.io/api/v3/openapi.json' |
| 32 | +); |
| 33 | + |
| 34 | +-- Override the base URL (replaces servers[0].url from the spec) |
| 35 | +create or modify rest client PetStoreModule.PetStoreStaging ( |
| 36 | + OpenAPI: 'https://petstore3.swagger.io/api/v3/openapi.json', |
| 37 | + BaseUrl: 'https://staging.petstore.example.com/api/v3' |
| 38 | +); |
| 39 | +``` |
| 40 | + |
| 41 | +This generates: |
| 42 | +- All operations with correct HTTP method, path, parameters, headers, body, and response type |
| 43 | +- Resource groups based on OpenAPI `tags` |
| 44 | +- Basic auth if the spec declares it at the top level |
| 45 | +- The spec stored inside the document for Studio Pro parity |
| 46 | + |
| 47 | +`BaseUrl` is optional. When omitted, `servers[0].url` from the spec is used. When provided, it overrides that value — useful when the spec points at production but you need to import against staging or a different version. |
| 48 | + |
| 49 | +**Preview without writing:** |
| 50 | +```sql |
| 51 | +describe contract operation from openapi 'specs/capital.json'; |
| 52 | +``` |
| 53 | + |
| 54 | +**After import:** the REST client is ready to use with `SEND REST REQUEST`. No manual operation definition needed. |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +## Approach 1: REST Client (Manual) |
19 | 59 |
|
20 | 60 | Define the API once as a REST client document, then call its operations from microflows. |
21 | 61 |
|
|
0 commit comments