|
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 | + |
| 35 | +This generates: |
| 36 | +- All operations with correct HTTP method, path, parameters, headers, body, and response type |
| 37 | +- Resource groups based on OpenAPI `tags` |
| 38 | +- Basic auth if the spec declares it at the top level |
| 39 | +- The spec stored inside the document for Studio Pro parity |
| 40 | + |
| 41 | +**Preview without writing:** |
| 42 | +```sql |
| 43 | +describe contract operation from openapi 'specs/capital.json'; |
| 44 | +``` |
| 45 | + |
| 46 | +**After import:** the REST client is ready to use with `SEND REST REQUEST`. No manual operation definition needed. |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## Approach 1: REST Client (Manual) |
19 | 51 |
|
20 | 52 | Define the API once as a REST client document, then call its operations from microflows. |
21 | 53 |
|
|
0 commit comments