Hi everyone,
I have a scenario involving two applications:
APP1: This application exposes a set of APIs.
APP2: In this application, I’ve created an entity to store API configuration details such as: Base URL (of APP1) API endpoints
In APP2, I’m storing these API values (base URL and endpoint) that correspond to services in APP1. In APP2, I have a detail screen for a specific record with a button. On clicking this button, I want to:
Retrieve the base URL and endpoint from the entity
Call the corresponding API exposed by APP1
Question: Is it possible to dynamically call an API using values (base URL + endpoint) stored in an entity in APP2? If yes, could you guide me on:
How to dynamically build and invoke the API call
Any OutSystems-specific considerations (since this is an ODC context)
Thanks in advance for your help!
Yes, it’s possible, but in OutSystems (O11) you can’t “create” REST methods at runtime. You must have at least one consumed REST API defined at design time, and then you use its extensibility hooks (OnBeforeRequest / OnBeforeRequestAdvanced) to turn it into a dynamic caller.
Below is a practical pattern you can apply in your O11 context, even if APP2 is storing the configuration and APP1 exposes the APIs. The same concepts apply if/when you move to ODC (I’ll call out any differences).
POST_Generic
GET_Generic
OnBeforeRequest
/Customer/Create
/Order/Close
This lets you “dynamically” call whatever endpoint APP1 exposes, using data you stored in APP2.
In Service Studio, right‑click your module → Consume REST API… Consume REST APIs
Use any URL as a placeholder (e.g., https://dummy-base-url.com), since we’ll override it.
https://dummy-base-url.com
Create a method, for example:
Execute
/generic/{Endpoint}
On the REST API node:
Suppose you have APIConfig entity with attributes:
APIConfig
Id
Name
BaseURL
Endpoint
customers/create
HttpMethod
GET
POST
AuthType
Token
Username
Password
DefaultPayload
On the detail screen, you have a record of APIConfig.
On your button’s screen action:
Fetch the APIConfig record (already on the screen).
Build the request:
APIConfig.Endpoint
APIConfig.DefaultPayload
Call GenericCallerAPI.Execute with:
GenericCallerAPI.Execute
Body
In the OnBeforeRequest callback of your generic REST API:
Inputs: Request (record with URL, Headers, etc.) and your custom inputs if needed.
Request
Steps:
Request.BaseURL
Because callbacks don’t directly know which APIConfig was used, you typically:
ConfigId
Execute(ConfigId: APIConfig.Id)
Request.Headers
Pseudo logic in OnBeforeRequest:
// Input: Request, ConfigId APIConfig = GetAPIConfigById(ConfigId) Request.BaseURL = APIConfig.BaseURL // Optionally adjust Request.UrlPath if needed: Request.UrlPath = "/" + APIConfig.Endpoint // Headers If APIConfig.AuthType = AuthType.Token { Request.Headers.Add("Authorization", "Bearer " + APIConfig.Token) }
This pattern leverages the “REST customization capabilities” OutSystems provides for advanced use cases such as custom authentication and dynamic headers Consume REST APIs.
You mentioned ODC context, but this question is tagged O11, so:
OnBeforeRequestAdvanced
Since both apps are in the same OutSystems O11 environment, consider:
Your dynamic “endpoint” approach is more appropriate when:
If you share a bit about how different the payloads/endpoints are (all similar or completely different), I can propose a more concrete structure for the generic method (number of methods, input types, error handling, etc.).
Hello Gowtham,May I ask you if both applications are in ODC? If so, why don't you use service actions instead of the exposed API?There are a few (but very important) advantages over API calls. Even if you still need the API for non-OutSystems apps, you can still have the Service Action to use with ODC applications.If you don't want to use service actions because you already have the API and want to use it, or because APP1 is not in ODC, you can just "consume" the API in your APP2 (assuming APP2 is an ODC app and the API is a REST api.The point is: why do you need to store the Base URL and endpoints in an Entity? What's your use case?The short answer is yes, you can dynamically define the base URL or endpoints in different ways, but in most scenarios there is no need to do that... Hence my questions.Cheers!
Thanks @Eduardo Jauch for your reply.
My both apps are in ODC
My use case here is: I need to create a test manager application to do the testing for server action created during the development. The test manager app is generic and independent of all other application. It should not have any direct reference between the application. So if any developer creates a server action and needs to test their action, they just need to expose that action as an API and configure that endpoint in the test manager action. Through test manager application I should be able to call that server action.
Ok. I understand the use case now.I still think the best approach would still be to use a service action.For your use case, there are some benefits, like the fact you don't need to keep the base url/endpoints (and parameters/output structures) in a configuration entity.Inside app2, when you make the reference for the service action in app1, it creates a "weak reference", as a service action is a REST endpoint (without the extra work).This means App1 will never really care about App2 and it will not impact its deployments in any way.But yes, if the tester does not have access to the make references to the application, or if the applications are not in the same organization, it's not possible to do it this way. Neo gave you some ways of doing it using REST :)Cheers!
The solution provided by @OutSystems Neo works perfect for my scenario. the solution is dynamically replace the endpoint using the On_Before_Request callback action when consuming the API.
Thanks you