In today’s software world, APIs (Application Programming Interfaces) are the foundation of integration. Whether your Oracle APEX application needs to connect with mobile apps, third-party platforms, or internal systems, APIs make it possible.
With Oracle APEX, you can do more than build web applications. You can also:
- Expose your database as REST APIs – share data and business logic securely.
- Consume REST APIs from other systems – bring external information directly into your app.
What You’ll Learn in This Blog
- What API-First means in APEX.
- How to create REST APIs in Oracle APEX.
- How to expose your data with GET, POST, PUT, and DELETE endpoints.
- How to consume external APIs in APEX.
- Best practices for beginners
1. What Does API-First Mean?
- Your APEX app can use these services.
- A mobile app can also use the same services.
- No duplicate logic—just one API serving many clients.
- Your APEX app can call this API.
- Other systems can also call it directly.
2. Setting Up REST APIs in Oracle APEX
Steps to Create a REST API
- Log in to SQL Workshop in APEX.
- Go to RESTful Services.
- Create a Module → this is like a folder that groups related APIs.
- Example:
hr_api
for HR-related endpoints. - Add Templates → these define the URL paths
- Example:
/employees/
. - Add Handlers → these define what happens when someone calls your API.
- GET → fetch data.
- POST → insert new data.
- PUT → update existing data.
- DELETE → remove data.
3. Examples of REST API Methods in APEX
GET (Fetch All Data)
/employees/
SELECT employee_id, first_name, last_name, salary
FROM employees;
Returns a JSON list of all employees.
GET by ID (Fetch One Employee)
/employees/:id
SELECT employee_id, first_name, last_name, salary
FROM employees
WHERE employee_id = :id;
Returns just one employee based on the ID passed in the URL.
POST (Insert New Employee)
/employees/
BEGIN
INSERT INTO employees (employee_id, first_name, last_name, salary)
VALUES (:employee_id, :first_name, :last_name, :salary);
END;
Send a JSON body like this:
{
"employee_id": 101,
"first_name": "John",
"last_name": "Doe",
"salary": 5000
}
This inserts a new record into the database.
PUT (Update Employee)
/employees/:id
BEGIN
UPDATE employees
SET salary = :salary
WHERE employee_id = :id;
END;
Updates the employee’s salary.
DELETE (Remove Employee)
Endpoint: /employees/:id
BEGIN
DELETE FROM employees
WHERE employee_id = :id;
END;
Deletes the employee with the given ID.
1. GET Method (Fetch Data from APEX API)
Suppose you expose an Employee REST API in APEX at:
https://oracleapex.com/ords/hr/employees/
DECLARE
l_response CLOB;
BEGIN
l_response := apex_web_service.make_rest_request(
p_url => 'https://oracleapex.com/ords/hr/employees/',
p_http_method => 'GET'
);
dbms_output.put_line('Response: ' || l_response);
END;
/
Use case: Fetch employee details from your APEX REST API.
2. POST Method (Insert New Data into APEX API)
Suppose you want to insert a new employee record:
API: https://oracleapex.com/ords/hr/employees/
DECLARE
l_response CLOB;
BEGIN
l_response := apex_web_service.make_rest_request(
p_url => 'https://oracleapex.com/ords/hr/employees/',
p_http_method => 'POST',
p_body => '{"employee_id": 207, "first_name": "Vikas", "last_name": "Kumar", "email": "vikas.kumar@example.com"}',
p_wallet_path => null,
p_content_type => 'application/json'
);
dbms_output.put_line('Response: ' || l_response);
END;
/
Use case: Add new employee details to APEX REST table.
3. PUT Method (Update Existing Data)
Suppose you want to update employee 207’s email:
API: https://oracleapex.com/ords/hr/employees/207
DECLARE
l_response CLOB;
BEGIN
l_response := apex_web_service.make_rest_request(
p_url => 'https://oracleapex.com/ords/hr/employees/207',
p_http_method => 'PUT',
p_body => '{"email": "vikas.new@example.com"}',
p_wallet_path => null,
p_content_type => 'application/json'
);
dbms_output.put_line('Response: ' || l_response);
END;
/
Use case: Update existing employee details.
4. DELETE Method (Remove a Record)
Suppose you want to delete employee 207:
API: https://oracleapex.com/ords/hr/employees/207
DECLARE
l_response CLOB;
BEGIN
l_response := apex_web_service.make_rest_request(
p_url => 'https://oracleapex.com/ords/hr/employees/207',
p_http_method => 'DELETE'
);
dbms_output.put_line('Response: ' || l_response);
END;
/
Use case: Delete a record from your APEX REST API.
Key Notes:
- API URL Format in APEX:
https://oracleapex.com/ords/schema/module/resource/
Example: https://oracleapex.com/ords/hr/employees/
- Methods:
- GET → Fetch data
- POST → Insert new record
- PUT → Update existing record
- DELETE → Remove record
- Testing Tools:
Before calling in PL/SQL, test API in Postman. - Authentication:
- Public APIs work without auth.
- Secure APIs need Basic Auth / OAuth2.
4. Consuming External APIs in Oracle APEX
You don’t just create APIs—you can also use APIs from other systems inside APEX.
Ways to consume external APIs:
- Web Source Modules → treat an API as a data source in APEX (like a table).
- PL/SQL APIs →
APEX_WEB_SERVICE
or APEX_EXEC
.
Example: Call a Weather API
DECLARE
l_response CLOB;
BEGIN
l_response := apex_web_service.make_rest_request(
p_url => 'https://api.weatherapi.com/v1/current.json?key=YOUR_KEY&q=Delhi',
p_http_method => 'GET'
);
dbms_output.put_line(l_response);
END;
This fetches weather data in JSON format, which you can then show in a report, chart, or page item.
5. Best Practices for Beginners
Design First – Write down your endpoints before coding. Tools like Postman.
Organize APIs – Group related APIs in modules (HR, Finance, etc.).
Secure Everything – Use Authentication (OAuth2, Basic Auth, or APEX sessions). Never leave APIs open.
Keep It Reusable – Write APIs so they can be used by APEX, mobile apps, or other systems.
Test with Postman – Always test APIs separately before using them in your app.
Why Building and Consuming REST APIs in APEX Matterses
- Future-ready → Connect your APEX apps to mobile, cloud, or third-party platforms effortlessly.
- Faster integration → Share data securely without direct database access—just expose REST APIs.
- Cleaner architecture → Keep business logic inside APIs instead of scattered across page processes.
Conclusion
Oracle APEX with ORDS makes building and consuming REST APIs straightforward and powerful. You can:
- Expose your tables and PL/SQL as secure, reusable REST APIs.
- Consume APIs from external systems directly in your APEX apps.
- Create modern, scalable, and integrated applications—all within the APEX environment.
Whether you’re working with GET, POST, PUT, or DELETE, mastering REST APIs in APEX is a core skill for developers building enterprise-ready solutions today.
Post a Comment
0Comments