Search This Blog

Showing posts with label Create a REST Data Source in APEX. Show all posts
Showing posts with label Create a REST Data Source in APEX. Show all posts

Tuesday, July 1, 2025

How do I Create a REST Data Source in APEX

 Introduction

In Oracle APEX, creating a REST Data Source allows your application to interact with external or internal RESTful services, bringing in live data without the need to store it in your local database. This is especially useful when working with cloud APIs, microservices, or shared enterprise data sources. By defining a REST Data Source, you can display, search, and even manipulate external data directly within APEX components like reports, charts, and forms. This approach supports modern, dynamic application development where real-time data access and integration are key.

To create a REST Data Source in Oracle APEX, follow these detailed steps. A REST Data Source allows your APEX application to query external RESTful web services as if they were local database tables. This is particularly useful when integrating cloud services, third-party APIs, or Oracle REST-enabled SQL.

  1. Open APEX and Access Shared Components
    Start by opening your APEX application. From the application home screen, click on Shared Components in the side menu. Under the Data Sources section, select REST Data Sources.

  2. Create a New REST Data Source
    Click on the Create button to begin the REST Data Source wizard. You will be prompted to select the type of REST Data Source. You can choose from:

    • Web Source (for external REST APIs),

    • Oracle REST Data Services (ORDS),

    • or Remote SQL (for querying remote Oracle databases).

  3. Enter the REST Endpoint URL
    Provide the RESTful endpoint URL. For example, if integrating a weather API:

    https://api.weatherapi.com/v1/current.json?q=NewYork&key=yourapikey
    

    You can also parameterize the URL to accept bind variables.

  4. Set HTTP Method and Authentication
    Choose the HTTP method, usually GET for data retrieval.
    Under Authentication, choose one of the following depending on the API:

    • None (if public),

    • Basic Authentication (username/password),

    • OAuth2 (for token-based APIs),

    • HTTP Header (for APIs requiring API keys or tokens in headers).
      Define any required HTTP headers, query parameters, or authentication tokens.

  5. Test the Connection
    Click on the Test button to make sure your API call works and returns data. If the test is successful, APEX will analyze the response and attempt to detect the JSON or XML structure.

  6. Configure Response Structure
    APEX will allow you to select the data structure that represents the rows of your virtual table. This is typically a JSON array within the API response. For example, from:

    { "weather": [ { "city": "New York", "temp": "85" } ] }
    

    you would select weather as the data path.

  7. Define Columns and Data Types
    APEX will automatically detect the fields and assign data types based on the sample response. You can rename columns, assign friendly labels, and adjust data types if needed.

  8. Finish and Save the REST Data Source
    Review the summary screen and click Create REST Data Source. You now have a REST Data Source available in your application.

  9. Use the REST Data Source in Components
    You can now use this REST Data Source in Classic Reports, Interactive Reports, Charts, and more. When creating a region, choose REST Data Source as the data source type and select the one you created.

  10. Optional: Add Filters and Parameters
    You can create bind variables in your URL to make the REST call dynamic. For instance, replacing a fixed city with a page item:

https://api.weatherapi.com/v1/current.json?q=&P1_CITY.&key=yourapikey

You can also configure pagination if the API supports it.

Using REST Data Sources effectively brings external data directly into APEX without replication. It’s a powerful method to make your application more dynamic, scalable, and integrated with modern services.

  1. Navigate to REST Data Sources:

    • Access the APEX App Builder.

    • Select the desired application.

    • Go to Shared Components.

A screenshot of a computer

AI-generated content may be incorrect.

  • Click on REST Data Sources.

A screenshot of a computer

AI-generated content may be incorrect.

  1. Initiate Creation:

    • Click the Create button.

  • Choose From Scratch and proceed.

A screenshot of a computer

AI-generated content may be incorrect.

Conclusion
Creating a REST Data Source in APEX enables you to build responsive, data-driven applications that communicate seamlessly with other systems. With just a few configuration steps, you can pull in external data, authenticate securely, and use that data across your APEX pages. Whether you're consuming a public API or integrating with enterprise systems, REST Data Sources provide the flexibility and power to expand your application's capabilities far beyond the local Oracle database.